Ubuntu – How To Login to VPS Using SSH/RSA Keys

keysopensshssh

I followed the instructions here and created a set of ssh keys (rsa) whilst logged into a vps as root. Encryption level 4096 as suggested…

The keys were already on the host so no need to transfer…

But the instructions fell apart at:

"You can make sure this worked by doing:"

ssh <username>@<host>

That's it, I don't understand what I need to do next. i.e. root@vpsIPaddress.

1 – Where do I do that?
2 – Can I use the same to login as a different user?

I cant get past this point as the instructions seem very unclear to me as to how I actually login using the keys instead of the password.

The lines below are in the sshd_config (but not sure what the ssh_config is for?)

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  %h/.ssh/authorized_keys
AuthorizedKeysFile /etc/ssh/rootuser/authorized_keys

In the home/ubuntu/.ssh directory there is an authorized_keys file too.

Hope that is enough info.

Best Answer

I don't quite understand what you mean by 'the keys were on the host, so no need to transfer', but think it might be due to you creating the keys on the VPS, rather than the client machine (your desktop). This is the wrong way up, which is a really common mistake when you're getting used to this system.

The keys are supposed to be created on the client, on a per-user basis, the default location for an Ubuntu client is the /home/username/.ssh/ directory. The private key which shouldn't be shared, is called id_rsa by default, the public key is called id_rsa.pub by default. If you're connecting from a windows client, I think the keys are in C:\Users\username\.ssh\.

You then share your public key with the (host) server, which puts the key in an authorised keys file. The command to do this is:

ssh-copy-id <username>@<host>

Where <username> is the username that you want to log in as on the VPS, and <host> is the IP address of the VPS. There are further things to add to this command if you have chosen a different name or location for your created ssh keys, or if your server uses a non-standard port for ssh.

This file holds keys which are allowed to be used to log on as that user, on that system, from your desktop machine, and any other machines that are authorised. The authorised keys file is normally also per-user, but on the host system. If it is a per-user file, it'll be found at /home/username/.ssh/authorized_keys.

Related Question