Trying to connect to my new droplet with ssh (public key added), after about 30 seconds or so get:

Connection closed by my-pub-ip-address port 22

Ran it with -vvv option and got this:

OpenSSH_8.6p1, OpenSSL 1.1.1k  25 Mar 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname my-pub-ip-address is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/user/.ssh/known_hosts2'
debug3: ssh_connect_direct: entering
debug1: Connecting to my-pub-ip-address [my-pub-ip-address] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 0
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/user/.ssh/id_xmss type -1
debug1: identity file /home/user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to my-pub-ip-address:22 as 'root'
debug1: load_hostkeys: fopen /home/user/.ssh/known_hosts: No such file or directory
debug1: load_hostkeys: fopen /home/user/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug3: order_hostkeyalgs: no algorithms matched; accept original
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
Connection closed by my-pub-ip-address port 22

Any idea what’s wrong?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi @nikSeal,

It seems to me like your Key is not being picked up. What I’ll recommend is trying the following command:

ssh -i /path/to/id_rsa.pub user@XXX.XXX.XXX.XXX

Where /path/to/id_rsa.pub is the path to your public ssh key and XXX.XXX.XXX.XXX is your Droplet’s IP address.

If this doesn’t work as well, you can use the DigitalOcean’s recovery console to enter your Droplet and see if your key has been properly added to the /root/.ssh/authorized_keys file. You can read more about the recovery console here:

https://docs.digitalocean.com/products/droplets/resources/recovery-console/

  • Hi @KFSys, thanks for your answer.

    I tried ssh with -i flag (Googled it) - didn’t work.

    Logged in to recovery console and checked the key in /root/.ssh/ - it’s there, my pub key that is.

    Not having a known_hosts (per -vvv flag) file - is this a problem? I’ve never connected with ssh anywhere before.

    • Hi @nikSeal,

      I see you were able to resolve the issue, I"m glad to hear that!

      Anyway, to answer your question, not having a known_hosts file is not a problem.