Search code examples
gitgithubsshssh-keyspublic-key

SSH - Permission denied (publickey) on server


I am trying to use git on my shared hosting on Hostgator but I am having issues establishing a connection with Github. I already tried tons of answers online but nothing have changed so far.

These are the steps that I followed in order to achieve that (I used this github guide):

On my machine,

1. I made a new key with ssh-keygen -t ed25519 -C "myemail@address.com"

2. I saved it into the file ~/.ssh/remote_github.pub, the file has no passphrase

3. Then I ran eval "$(ssh-agent -s)"

4. In my ~/.ssh/config file I specified

Host *
  Hostname IP-ADDRESS-OF-SERVER
  AddKeysToAgent yes
  IdentityFile ~/.ssh/remote_github
  IdentitiesOnly yes

5. I copied the public key with pbcopy < ~/.ssh/remote_github.pub and saved it into my github account

6. Then I ran ssh-copy-id -i ~/.ssh/remote_github.pub myuser@remoteserver

And the answer was

INFO: Source of key(s) to be installed: "/Users/mattiabombelli/.ssh/remote_github.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: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
mbombelli@192.254.233.200's password:

After inserting the password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'myuser@remoteserver'"
and check to make sure that only the key(s) you wanted were added.

Checking the authorized_keys file on the server I see the same exact public key remote_github.pub stored in my machine*

7. But at this point, if I try to run ssh -T -v git@github.com

This is what I get:

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Connecting to github.com [140.82.113.3] port 22.
debug1: Connection established.
debug1: identity file /home1/mbombelli/.ssh/identity type -1
debug1: identity file /home1/mbombelli/.ssh/identity-cert type -1
debug1: identity file /home1/mbombelli/.ssh/id_rsa type -1
debug1: identity file /home1/mbombelli/.ssh/id_rsa-cert type -1
debug1: identity file /home1/mbombelli/.ssh/id_dsa type -1
debug1: identity file /home1/mbombelli/.ssh/id_dsa-cert type -1
debug1: identity file /home1/mbombelli/.ssh/id_ecdsa type -1
debug1: identity file /home1/mbombelli/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version babeld-c863b32e
debug1: no match: babeld-c863b32e
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home1/mbombelli/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home1/mbombelli/.ssh/identity
debug1: Trying private key: /home1/mbombelli/.ssh/id_rsa
debug1: Trying private key: /home1/mbombelli/.ssh/id_dsa
debug1: Trying private key: /home1/mbombelli/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

I also made sure to change the permissions on the server with chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys but the answer is always Permission denied (publickey).

What am I doing wrong? Or missing?

Thank you.

*the authorized_keys file contains also another ssh-rsa public key.


Solution

  • First, if your private key has no passphrase, you don't need anything related to ssh-agent.

    Second, "he authorized_keys file on the server I see the same exact public key remote_github.pub stored in my machine*" means you can connect to your server from your local machine.
    It has nothing to do with GitHub.

    If you want to connect to GitHub from the remote server, then you would need for that remote server account to have your private key.

    If you want to connect to GitHub from your local machine, then Hostgator is not involved at all.