R1
By:
R1

SSH key verification is failing.

November 21, 2014 9.3k views

I have uploaded public and created droplet to use public key. I tried to login using ssh root@xx.xx...

It is consistently failing with error host key verification failed. I am creating key on Mac and copy/paste to SSH key
Any idea ?

2 Answers

The host key and the SSH key you use to log in are two different things.

One authenticates the host for you to verify (the host key), and the other one is the key you use to identify yourself and authenticate to your account.

If you delete a droplet and create a new one with the same IP, for instance, you will see a SSH host key verification failed because the SSH host key of your first droplet and the second one aren't the same. This is a security feature so you can detect man in the middle attacks.

When you restore a snapshot, unfortunately DigitalOcean messes around a lot of files, especially the SSH ones. Even if you carefully prepare your host key, note down its fingerprint and then snapshot hoping to restore it as-is, you'll find that they heavily modify your disk image upon restoration, leading to these sort of errors.

The only "safe" way to prevent MitM attacks on your box is this:

Take a snapshot, restore it, reset the root password, log in through web console, check the SSH host key fingerprint, then log in over SSH verifying the key.

If you don't want to risk filesystem corruption when resetting the root password, restore your droplet using a password rather than the SSH keys. You will be asked to change it on first log in.

  • Thanks for answer.
    I have created multiple droplets and deleted them and also created multiple time ssh and uploaded them.
    I am also noticing that IP address does not get changed..
    Which is the best way to start all over again ? I need to use CoreOS which needs SSH to login.

  • There's no reason to start over again, your droplets are working fine. The error message you get when you try to log in should have pretty specific directions on where the offending line is located in your known_hosts file - this holds the previously seen SSH host key.

  • Following is error output

    ssh root@104.236.185.229
    The authenticity of host '104.236.185.229 (104.236.185.229)' can't be established.
    RSA key fingerprint is 3d:05:b3:09:dd:4d:b1:2a:d6:80:e6:c0:d9:93:04:85.
    Are you sure you want to continue connecting (yes/no)?

    Host key verification failed.

    My known_hosts file is empty

  • If you read my post carefully, I explain why this "error" appears. Simply follow the instructions given to you on your terminal.

  • Now this seems a different problem..

    I am able to login and I am using ssh to login why it is asking root password..
    My private key should be sufficient to identify me..

    ssh root@104.236.184.105
    The authenticity of host '104.236.184.105 (104.236.184.105)' can't be established.
    RSA key fingerprint is 26:2e:54:13:4d:97:aa:3d:32:36:74:15:c4:7e:24:bf.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '104.236.184.105' (RSA) to the list of known hosts.
    root@104.236.184.105's password:

  • Correct, if the public key doesn't work, it's either because it wasn't selected when you provided the droplet or your client is not set correctly to send the key upon log in.

    You can use ssh with the '-v' flag (you can add more v's for more verbose output) to see why it's doing this.

  • Thanks for suggesting ssh -v option.

    I have uploaded idrsa.pub ( public key ) to DigitalOcean.
    Now from the following log, I can observe that when ssh client offers id
    rsa which is private key correspond to id_rsa.pub key it should have been accepted.

    Why it is naming id_rsa "public Key", it is private key, that is my first question..

    Logic falls through and finally it asks for password..

    Is it correct interpretation..

    =====

    ebug1: SSH2MSGSERVICEACCEPT received
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/digitalocean
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/id
    rsa
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Trying private key: /Users/bhatr011/.ssh/id_dsa
    debug1: Next authentication method: keyboard-interactive
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: password

    root@104.236.184.105's password:
  • Why is it trying idrsa rather than id_rsa? Perhaps there's a mistake in your configuration files?

    It's calling it a public key because it's public key authentication. But the content of idrsa should be your private key, and idrsa.pub should contain your public key.

  • No it is trying id_rsa ..I believe it is my error, cut/paste

    =============
    Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/digitalocean
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/idrsa
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Trying private key: /Users/bhatr011/.ssh/id
    dsa
    debug1: Next authentication method: keyboard-interactive
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: password

    root@104.236.184.105's password:

    I have uploaded idrsa.pub ( DigitalOcean) and my ssh client is offering idrsa ( private key ) which I believe should have worked.

  • Can you try with more than one -v? That log is very short.

  • Full log

    ======
    localhost:.ssh bhatr011$ ssh -v root@104.236.184.105
    OpenSSH5.9p1, OpenSSL 0.9.8za 5 Jun 2014
    debug1: Reading configuration data /etc/ssh
    config
    debug1: /etc/sshconfig line 20: Applying options for *
    debug1: /etc/ssh
    config line 53: Applying options for *
    debug1: Connecting to 104.236.184.105 [104.236.184.105] port 22.
    debug1: Connection established.
    debug1: identity file /Users/bhatr011/.ssh/idrsa type 1
    debug1: identity file /Users/bhatr011/.ssh/id
    rsa-cert type -1
    debug1: identity file /Users/bhatr011/.ssh/iddsa type -1
    debug1: identity file /Users/bhatr011/.ssh/id
    dsa-cert type -1
    debug1: Remote protocol version 2.0, remote software version OpenSSH6.6p1-hpn14v4
    debug1: match: OpenSSH
    6.6p1-hpn14v4 pat OpenSSH*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH5.9
    debug1: SSH2
    MSGKEXINIT sent
    debug1: SSH2
    MSGKEXINIT received
    debug1: kex: server->client aes128-ctr hmac-md5 none
    debug1: kex: client->server aes128-ctr hmac-md5 none
    debug1: SSH2
    MSGKEXDHGEXREQUEST(1024<1024<8192) sent
    debug1: expecting SSH2MSGKEXDHGEXGROUP
    debug1: SSH2
    MSGKEXDHGEXINIT sent
    debug1: expecting SSH2MSGKEXDHGEXREPLY
    debug1: Server host key: RSA 26:2e:54:13:4d:97:aa:3d:32:36:74:15:c4:7e:24:bf
    debug1: Host '104.236.184.105' is known and matches the RSA host key.
    debug1: Found key in /Users/bhatr011/.ssh/known
    hosts:1
    debug1: sshrsaverify: signature correct
    debug1: SSH2MSGNEWKEYS sent
    debug1: expecting SSH2MSGNEWKEYS
    debug1: SSH2MSGNEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2MSGSERVICEREQUEST sent
    debug1: SSH2
    MSGSERVICEACCEPT received
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/digitalocean
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/idrsa
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Trying private key: /Users/bhatr011/.ssh/id
    dsa
    debug1: Next authentication method: keyboard-interactive
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: password

    root@104.236.184.105's password:
  • Again, can you try with more than one -v?

  • localhost:.ssh bhatr011$ ssh -vv root@104.236.184.105
    OpenSSH5.9p1, OpenSSL 0.9.8za 5 Jun 2014
    debug1: Reading configuration data /etc/ssh
    config
    debug1: /etc/sshconfig line 20: Applying options for *
    debug1: /etc/ssh
    config line 53: Applying options for *
    debug2: sshconnect: needpriv 0
    debug1: Connecting to 104.236.184.105 [104.236.184.105] port 22.
    debug1: Connection established.
    debug1: identity file /Users/bhatr011/.ssh/id
    rsa type 1
    debug1: identity file /Users/bhatr011/.ssh/idrsa-cert type -1
    debug1: identity file /Users/bhatr011/.ssh/id
    dsa type -1
    debug1: identity file /Users/bhatr011/.ssh/iddsa-cert type -1
    debug1: Remote protocol version 2.0, remote software version OpenSSH
    6.6p1-hpn14v4
    debug1: match: OpenSSH6.6p1-hpn14v4 pat OpenSSH*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH
    5.9
    debug2: fd 3 setting ONONBLOCK
    debug1: SSH2
    MSGKEXINIT sent
    debug1: SSH2
    MSGKEXINIT received
    debug2: kex
    parsekexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: kex
    parsekexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-dss
    debug2: kex
    parsekexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
    debug2: kex
    parsekexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
    debug2: kex
    parsekexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex
    parsekexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex
    parsekexinit: none,zlib@openssh.com,zlib
    debug2: kex
    parsekexinit: none,zlib@openssh.com,zlib
    debug2: kex
    parsekexinit:
    debug2: kex
    parsekexinit:
    debug2: kex
    parsekexinit: firstkexfollows 0
    debug2: kex
    parsekexinit: reserved 0
    debug2: kex
    parsekexinit: curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: kex
    parsekexinit: ssh-rsa,ssh-dss,ssh-ed25519
    debug2: kex
    parsekexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
    debug2: kex
    parsekexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
    debug2: kex
    parsekexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex
    parsekexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex
    parsekexinit: none,zlib@openssh.com
    debug2: kex
    parsekexinit: none,zlib@openssh.com
    debug2: kex
    parsekexinit:
    debug2: kex
    parsekexinit:
    debug2: kex
    parsekexinit: firstkexfollows 0
    debug2: kex
    parsekexinit: reserved 0
    debug2: mac
    setup: found hmac-md5
    debug1: kex: server->client aes128-ctr hmac-md5 none
    debug2: macsetup: found hmac-md5
    debug1: kex: client->server aes128-ctr hmac-md5 none
    debug1: SSH2
    MSGKEXDHGEXREQUEST(1024<1024<8192) sent
    debug1: expecting SSH2MSGKEXDHGEXGROUP
    debug2: dh
    genkey: priv key bits set: 142/256
    debug2: bits set: 509/1024
    debug1: SSH2
    MSGKEXDHGEXINIT sent
    debug1: expecting SSH2MSGKEXDHGEXREPLY
    debug1: Server host key: RSA 26:2e:54:13:4d:97:aa:3d:32:36:74:15:c4:7e:24:bf
    debug1: Host '104.236.184.105' is known and matches the RSA host key.
    debug1: Found key in /Users/bhatr011/.ssh/known
    hosts:1
    debug2: bits set: 530/1024
    debug1: sshrsaverify: signature correct
    debug2: kexderivekeys
    debug2: setnewkeys: mode 1
    debug1: SSH2
    MSGNEWKEYS sent
    debug1: expecting SSH2
    MSGNEWKEYS
    debug2: set
    newkeys: mode 0
    debug1: SSH2MSGNEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2MSGSERVICEREQUEST sent
    debug2: service
    accept: ssh-userauth
    debug1: SSH2MSGSERVICEACCEPT received
    debug2: key: /Users/bhatr011/.ssh/digitalocean (0x7fbe8b41e250)
    debug2: key: /Users/bhatr011/.ssh/id
    rsa (0x7fbe8b410ac0)
    debug2: key: /Users/bhatr011/.ssh/iddsa (0x0)
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/digitalocean
    debug2: we sent a publickey packet, wait for reply
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Offering RSA public key: /Users/bhatr011/.ssh/id
    rsa
    debug2: we sent a publickey packet, wait for reply
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Trying private key: /Users/bhatr011/.ssh/iddsa
    debug2: we did not send a packet, disable method
    debug1: Next authentication method: keyboard-interactive
    debug2: userauth
    kbdint
    debug2: we sent a keyboard-interactive packet, wait for reply
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug2: we did not send a packet, disable method
    debug1: Next authentication method: password
    root@104.236.184.105's password:

  • There's no indication that anything wrong is going wrong here, other than the key not matching what the server is expecting. Make sure you're using the private key that is matching the public key you uploaded on DigitalOcean and chose when you created the server.

No idea what is happening.
You may try to edit/create a client ssh config file and set the IdentityFile explicitly.

This is what I usually do with linux system, convert to mac.

vim ~/.ssh/config # (it should be /Users/bhatr011/.ssh/config in your case)
# Add the following config
Host prefferedhostname
    User root
    Hostname 104.236.184.105
    Port 22
    PreferredAuthentications publickey
    IdentityFile /path/to/your/private/key

Then you should be able to ssh to your droplet simply by typing

ssh prefferedhostname
Have another answer? Share your knowledge.