SSH public key authentication
From HostThyself
SSH is a secure way of signing on to a remote server.
Public key authentication is a way of signing on the the remote server using a public key. Using this method, a password is not require. It is advantageous when you have a lot of password to remember or you want to script some task with having to interactively sign in.
[edit] Setting up SSH public key authentication
Before we start, some terminology
- server - the remote server to sign into
- client - the system from with the connection originate
[edit] Generate Key
A RSA key pair must be generated on the client system. Two files will be generated.
- id_rsa.pub - The public portion of the key pair. This file should be copied to the server being connected to.
- id_rsa - The private portion needs to remain on a secure local area of the client system
The key generation is done with the ssh-keygen (if ~/.ssh does not exist, create it first.)
ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
[edit] Copy Public Key to Server
The generated public key should be appended to the file ~/.ssh/authorized_keys on the server.
From the client,
scp ~/.ssh/id_rsa.pub username@example.com:
Sign on to the server,
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys rm ~/id_rsa.pub