1

To practice git I made the gituser create a bare repository in the directory /home/gituser/project.git. I later created a new user on my computer name Tom and I created sshkeys for it the ssh keys are stored in /home/Tom/.ssh directory. How would I be able to add the user Tom's public ssh key to gituser's repository so that Tom can commit and push changes to the repository? Both of the users have admin permissions on ubuntu 20.04 and only the gituser is in a group:dev. Note that both the users are on the same computer.

I know that the command to copy your public keys is :

ssh-copy-id -i ~/.ssh/id_rsa.pub <server>

but I am confused on what I can place for the server.

Outputs for gituser:

gituser@D-82I:~$ cd .ssh
-bash: cd: .ssh: No such file or directory
gituser@D-82I:~$ pwd
/home/gituser
gituser@D-82I:~$ ls
project.git
gituser@D-82I:~$ cd project.git/
gituser@D-82I:~/project.git$ ls
HEAD  branches  config  description  hooks  info  objects  refs

Outputs for user Tom and Errors:

Tom@DESKTOP-AVNQ82I:~$ ls
Tom@DESKTOP-AVNQ82I:~$ pwd
/home/Tom
Tom@DESKTOP-AVNQ82I:~$ cd .ssh
Tom@DESKTOP-AVNQ82I:~/.ssh$ ls
id_rsa  id_rsa.pub
Tom@DESKTOP-AVNQ82I:~/.ssh$ ssh-copy-id -i ~/.ssh/id_rsa.pub ~gituser/.ssh/authorized_keys
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/Tom/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname /home/gituser/.ssh/authorized_keys: Name or service not known
Tom@DESKTOP-AVNQ82I:~$ git remote add origin gituser@serverName:/home/gituser/project.git
fatal: not a git repository (or any of the parent directories): .git

1 Answer 1

1

server should be:

  • the remote user account gituser which created the bare repo
  • the remote server hostname or IP address where the repo was created.

That means server:~gituser/.ssh/authorized_keys will receive Tom public SSH key.

From Tom's workstation, you can add the remote URL to your local repository:

git remote add origin gituser@serverName:/home/gituser/project.git

And push to it.

Sign up to request clarification or add additional context in comments.

12 Comments

Hi thanks for the reply I am still having trouble I have added the console outputs trying to add Tom to the git server but its still not working. Could you please take another look at it. The last 2 inputs in the Outputs for user Tom and Errors section contains the errors.
@edgeselcuk The ssh-copy-id should be ssh-copy-id -i ~/.ssh/id_rsa.pub gituser/@servername
Hi sorry for the long wait but I have done ssh-copy-id -i ~/.ssh/id_rsa.pub gituser/@DESKTOP-AVNQ82I and now it gave me the error: /usr/bin/ssh-copy-id: ERROR: ssh: connect to host desktop-avnq82i port 22: Connection refused
@edgeselcuk sorry typo: It is gituser@servername, not gituser/@servername: no /.
Hi now it is giving me the error fatal: not a git repository (or any of the parent directories): .git
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.