SSH with keys (no passwords)

Abstract: Instructions on setting up a Linux computer (server) so you can log in (from your client) with ssh without having to enter a password (using keys).

Without a password, authentication is done with a key. To achieve password-less access, you need a key, and the computer you are logging in to needs to know about that key.
A Key has two parts – private and public. You keep the private part, you give the public part to anyone who needs to know you are who you say you are.

Generate a key on the client computer using:
ssh-keygen -t rsa
This will create two files:

File Description
~/.ssh/id_rsa Your private key
~/.ssh/id_rsa.pub Your public key

You need to add the contents of ~/.ssh/id_rsa.pub to the file ~/.ssh/authorized_keys on the server, logged in as the user you will be using:
cat ~/.ssh/id_rsa.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
This is the last time you will need to enter the password.
From now on, you can just connect using:
ssh user@server
Or, if you are logged on to the client as the same username, just
ssh-keygen -R ip-address

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *