Ubuntu – SSH Error: No supported authentication methods available (server sent public key)

16.04networkingssh

On an Ubuntu 16.04 system on Google GCP, I need to create a new user hello and allow other users to SSH to the system as user hello using their current SSH keys.

Here's what I did to add my SSH public key to hello's authorized_keys:

sudo useradd -m hello -s /bin/bash
sudo mkdir /home/hello/.ssh
sudo chown hello:hello -R /home/hello
sudo chmod 777 /home/hello/.ssh
sudo cat ~/.ssh/authorized_keys >> /home/hello/.ssh/authorized_keys
sudo chmod 700 /home/hello/.ssh/
sudo chmod 600 /home/hello/.ssh/authorized_keys

Problem: When I try to SSH to the server as hello user, I get the error

Disconnected: No supported authentication methods available (server sent public key)

/var/log/auth.log contains

Nov 4 17:37:05 hello sshd[27298]: error: Received disconnect from 174.63.124.9 port 62346:14: No supported authentication methods available [preauth]
Nov 4 17:37:05 hello sshd[27298]: Disconnected from 174.63.124.9 port 62346 [preauth]

What went wrong? Thank you!

Best Answer

You need to change the owner of the file authorized_keys after it is created, since it will be owned by the user running the script.

Adding this as last line to your script should do the trick.

sudo chown hello:hello /home/hello/.ssh/authorized_keys