Quick and dirty SSH Public Key Authentication



Every time I want to setup public key authentication over SSH I use this simplest guide. Today, I decided to share it.

 

Create a key pair on local machine:

$ ssh-keygen -t rsa

Output:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/dima/.ssh/id_rsa):

It will ask you for a passphrase. Enter a sequence of any characters to protect the key.

Output:

Enter passphrase (empty for no passphrase): y0urp@$$phr@se
Enter same passphrase again: y0urp@$$phr@se

Check if the public/private rsa key pair exists:

$ ls ~/.ssh/*rsa*

Output:

/home/user/.ssh/id_rsa
/home/user/.ssh/id_rsa.pub

id_rsa - the private rsa key. which must never be made available to anyone
id_rsa.pub - the public rsa key, which can be distributed to other computers

Copy your public key to the remote server:

sftp your.remote.server.net
sftp> mkdir .ssh
sftp> put .ssh/id_rsa.pub .ssh/authorized_keys2

Now you can connect via SSH to your remote server:

ssh -v your.remote.server.net