Six years ago, when I first started occasionally logging in to remote Linux servers, I must have missed a detail or two, because I started out by creating ssh key-pairs for my server access, and then I proceeded to never use them, instead typing my password each and every time I needed to access the VM. No more, I say.
Lest I forget: In the
~/.ssh/ directory is where the private and public keys are stored by default. So when we run
ssh-keygen this is typically where we go and find it. The public key needs to go to the VM you want to connect to and the private key needs to stay right where it is.
Create a file, if it doesn’t exist, and name it
config. Inside this file paste the following.
Host remote HostName 184.108.40.206 Port 22 IdentityFile ~/.ssh/id_rsa User root
In the above,
remote is the shorthand for this connection. The
HostName is the
url you wish to connect to. The
IdentityFile is the
private key matching the public key that we just copied to the server.
When this is setup, it becomes possible to access the remote server by referring to the shorthand instead of writing
$ ssh remote