Issue
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
Solution
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.
Answered By - VonC Answer Checked By - Katrina (WPSolving Volunteer)