I tried to make keys instead of password

February 15, 2019 188 views
DigitalOcean

I have ubuntu 16.04
I have disabled root login.
I have a user with sudo.

I made an ssh authentication key pair:
I tried to scp my public key but was told that the file doesnt exist.
I copied the public key to text edit on my mac.
I pasted it into a file I created in .ssh called authorizedkeys.
A file called authorized also appeared.
I changed the permissions in sshd
config to allow authorized keys and not allow password login.
I chmod 400 authorized keys and authorized.
I chmod 700 .ssh

The long and the short of it is that I cant get into my server, no password, no root, no keys, I dont even get aske for my phrase.

I hope I’m not completely stuffed cos I really dont want to destroy my droplet and start again.

Any ideas?
In case its not painfully obvious I am a complete noob and just working from a book so super easy answers would be appreciated.

Thanks all

1 Answer

Hey @sfrasera70137b785a5be62b45 !

I hope you didn’t disable root login first, then created a user and gave it sudo perms :S Always try to test new implementations before removing old ones.

Anyway, it looks like you misunderstood the way SSH keys work. In short:

  • On the remote server, you will have a public key inside ~/.ssh/authorized_keys. This file will be used to check if you may be authenticated.
  • On your personal client, you need to have a private key (id-rsa). This key will be used to authenticate with the remote server.

You should not chmod the authorized_keys with 400. Try to use the following:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

If you like to follow it, I have a tutorial made for this: Setting up SSH keys on Debian. It’s a tutorial for Debian but works on ubuntu as well. The only thing that changes is restarting the ssh service:

service ssh restart
Have another answer? Share your knowledge.