Ssh – Connection to remote with SSH denied (publickey)

ssh

I am trying to set up a digital ocean droplet for deployment with trellis but something has gone awry.

Im on windows, using vagrant im my project folder I try to ssh to it and get this readout:

vagrant@recfishwa:~$  ssh 198.166.218.143
Permission denied (publickey).

vagrant@recfishwa:~$  ssh -v 198.166.218.143
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 3: Applying options for *
debug1: /etc/ssh/ssh_config line 20: Deprecated option "useroaming"
debug1: Connecting to 189.166.218.143 [198.166.218.143] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/vagrant/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/vagrant/.ssh/id_ed25519-cert type -1
debug1: identity file /home/vagrant/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/vagrant/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 188.166.218.143:22 as 'vagrant'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-ed25519 SHA256:2R+kXXuJxz/ON3eeOmToiySqGtxCClQoXV98t9mmhNE
debug1: Host '188.166.218.143' is known and matches the ED25519 host key.
debug1: Found key in /home/vagrant/.ssh/known_hosts:6
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/vagrant/.ssh/id_ed25519
debug1: Offering RSA public key: /home/vagrant/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

I was hoping there would be a clue in there as I have run out of research. I did originally set the droplet up with an ssh I generated with putty_gen but have since deleted the key in settings and reset the root password in an attempt to gain access but no luck. I cannot even log into the DO console with the password for some reason even after the reset. Ihave reloaded vagrant. Im not sure if there is still a key associated with the droplet now. Anything obvious in the debug log?

Also can someone please confirm where I should store my keys on my local computer when running vagrant in my project dir and trying to connect to DO?

I also have cygwin configured with openssh and also Putty but still cannot connect no matter what I try.

Best Answer

Check /home/vagrant/.ssh/id_rsa for an existing RSA private SSH key. Make sure that the public key (should be located at /home/vagrant/.ssh/id_rsa.pub) exists on 188.166.218.143, or look at documentation for the command ssh-copy-id which will automatically copy the public key for you, providing that you have password authentication for the root (or whichever user you prefer) enabled. If you don't have the keys, generate them by using the command ssh-keygen -t rsa.

Otherwise, if you've totally locked yourself out of your droplet, you may need to open a support ticket with DigitalOcean... they're generally pretty good in their response times.

Vagrant usually copies the current user's SSH public key into the vagrant box. If this is broke, ensure that your key does exist in home directory (~/.ssh), and reinstall vagrant (save your instances and reinstall the package).