Today I have encountered an interesting issue. I am learning how to work with Ubuntu servers and this morning I have successfully set up a server with nginx for Django. However, I can’t figure out how did I manage to get the SSH authentication working.
I used PuTTYgen. I assigned my SSH public key to my droplet. But now when I try to create a new droplet, it ends up like that: I can log in to the server as root user, but whenever I try to add a new non-root user and assign the public key to it, then I am not able to log in as that user using SSH and I get the “Permission denied(Publickey)” response.
Here are the commands I use once I log in to the server for the first time as the root user:
adduser myuser
usermod -aG sudo myuser
su - myuser
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
Then I paste in the public key I got from the PuTTYgen and save it. And after that I do:
chmod 600 ~/.ssh/authorized_keys
Once this is done I check the /etc/ssh/sshd_config if the settings look like this:
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
And after that, when I switch back to the root user and I try to use the command,
ssh myuser@server_ip
it still doesn’t work…
Any ideas?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.