I host all of my Git repositories on a box that has a different port than normal SSH connections use, which causes git checkouts to be a bit of a pain in the butt.
So, in order to deal with this, any computer I plan on continually using for Git access, I add to the git user’s authorized_keys list. Here is the step by step I use to make it easy.
All of these commands are performed on the computer I want to grant permission to.
First, make sure I have a public ssh key.
cat .ssh/id_rsa.pub
Now, lets copy that public key to the Git server.
scp -P 8888 .ssh/id_rsa.pub git@YOUR_SERVER_ADDRESS:~
Using a remote SSH command, lets append our id_rsa.pub file to the authorized keys list, and then delete the file since we won’t be using it anymore.
ssh -p 8888 git@YOUR_SERVER_ADDRESS "cat id_rsa.pub >> .ssh/authorized_keys; rm id_rsa.pub"
Test the connection to make sure we can connect without a password. Just ssh and then exit immediately if it worked.
ssh git@YOUR_SERVER_ADDRESS -p 8888
Alright, so once that works, you have permission… but it still doesn’t deal with the port problem. To do that, we will create a .ssh host in the config file.
vi .ssh/config
You want to add something that looks like this:
host myserver
hostname YOUR_SERVER_ADDRESS
user git
port 8888
Once you’ve done that, save the file and exit.
Now, you should be able to clone your git repo without any problems. No more passwords, no more long git urls. Just beautiful simplicity.
git clone myserver:commentize.git