0

I have been having trouble over the last few days trying to connect to a github account.

I have:

  • Followed the guide to generate keys and add to github
  • Followed the troubleshooting guide on Permission denied (My MD5 hash locally matches that of the one in my github account.)
  • Tried verbose output when testing ssh connection

Here is the output for ssh -vT [email protected]

OpenSSH_7.5p1, OpenSSL 1.0.2l  25 May 2017
debug1: Reading configuration data /Users/[obfuscated]/.ssh/config
debug1: /Users/[obfuscated]/.ssh/config line 13: Applying options for *
debug1: /Users/[obfuscated]/.ssh/config line 24: Applying options for github.com
debug1: Reading configuration data /usr/local/etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: fd 5 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/[obfuscated]/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/[obfuscated]/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: [email protected]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: [email protected]
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

Something interesting here I have noticed is that I dont have debug1: Offering RSA public key: /Users/you/.ssh/id_rsa or debug1: Trying private key: /Users/you/.ssh/id_rsa in my debug. Almost as if that part is being skipped. I do have debug1: identity file /Users/[obfuscated]/.ssh/id_rsa type 1 though, so it seems like it has found the file.

Here is my .ssh/config:

Host localhost
  ControlMaster no

# default for all hosts
Host *
     ConnectTimeout 30
     ServerAliveInterval 30
     ControlMaster auto
     ControlPersist 60s
     HashKnownHosts yes
     GSSAPIAuthentication no
     IdentitiesOnly yes
     Compression yes

# github user
Host github.com
     HostName github.com
     User git
     PreferredAuthentications publicKey
     IdentityFile ~/.ssh/id_rsa

# the local raspberry pi dns ad block server
Host pi
     HostName [obfuscated]
     User pi
     IdentityFile ~/.ssh/pi_rsa

Permissions for ssh files

 8 -rw-r--r--   1 [obfuscated]  staff   802B Sep  9 21:45 config
 8 -rw-------   1 [obfuscated]  staff   3.2K Sep  9 21:16 id_rsa
 8 -rw-r--r--   1 [obfuscated]  staff   747B Sep  9 21:16 id_rsa.pub
 8 -rw-r--r--   1 [obfuscated]  staff   885B Sep  9 21:37 known_hosts
 8 -rw-------   1 [obfuscated]  staff   1.7K Oct 21  2016 pi_rsa
 8 -rw-r--r--   1 [obfuscated]  staff   405B Oct 21  2016 pi_rsa.pub
1
  • I am able to ssh into the pi with this config Commented Sep 10, 2017 at 6:42

1 Answer 1

1

Short answer: I had a typo in my .ssh/config.

PreferredAuthentications publicKey

should have had a lower case k

PreferredAuthentications publickey

How I discovered the issue:

On most systems the default private keys (~/.ssh/id_rsa, ~/.ssh/id_dsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn't need to run ssh-add path/to/key unless you override the file name when you generate a key.

By knowing this, I removed my custom config for github.com so that the SSH authentication agent would use my key by default.

This allowed me to connect. I then added back one line at a time until I found that PreferredAuthentications publicKey was not working. I googled it to check the syntax and found the issue was the upper case K.

You must log in to answer this question.

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