0

I'm trying to add a key to github and my server so my server can clone from github.

mkdir -p /root/.ssh
chmod 700 /root/.ssh
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2E.... GitHub
EOF
chmod 600 /root/.ssh/authorized_keys

cat > /root/.ssh/github.id_rsa <<EOF
-----BEGIN RSA PRIVATE KEY-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END RSA PRIVATE KEY-----
EOF
chmod 600 /root/.ssh/github.id_rsa

cat > /root/.ssh/config <<EOF
Host github.com
  Hostname github.com
  IdentityFile ~/.ssh/github.id_rsa
EOF
chmod 600 /root/.ssh/config

I added the public key to github and when I try and clone it doesn't connect. What am I doing wrong?

2 Answers 2

1

You created the SSH key in /root/.ssh/github.id_rsa but you use ~/.ssh/github.id_rsa in your SSH config. Unless you use your root account for accessing GitHub, git will look in the wrong place for the SSH key. It will look in /home/$USERNAME/.ssh/github.id_rsa instead of /root/.ssh/github.id_rsa.

I would recommend putting the SSH key into ~/.ssh/. If you want to use your old key, just move it there:

mv /root/.ssh/github.id_rsa /home/$USERNAME/.ssh/

where $USERNAME is your username.

1
  • @Jimmy Did this solve your problem? It should IMHO.
    – Pille
    May 19, 2017 at 16:56
0

shot in the dark here. Github allows 2 kinds of end points to clone. http and ssh. For example

https://github.com/python-diamond/Diamond.git

vs

[email protected]:python-diamond/Diamond.git

The https version doesn't use ssh keys. So make sure you are using the ssh version which will always start with [email protected]

1
  • Hi. Thank you for the comment. I'm afraid I am using the second one. Is it right that my key is in two halfs, private and public, and the public goes on github and the private goes on my server, or does the public have to go on both
    – Jimmy
    Feb 3, 2015 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .