Using SSH Keys to Log into Servers without Passwords

To save from constantly having to enter usernames and passwords when logging into remote servers it is possible to set up a key that can be used to open the connection. This document briefly describes how a key can be created and used.

Creating a new Key

Use ssh-keygen to create a new key

ssh-keygen -t rsa

Do not enter a pass phrase if this key is going to be used for automatic login (e.g., for cron backups). This should create two files, one containing the public key (usually ~/.ssh/id_rsa.pub and one containing the private key file (usually ~/.ssh/id_rsa).

Copy the public key to the remote machine you want to connect to (in this case example.com)

scp ~/.ssh/id_rsa.pub example.com:

Now log into that machine using ssh and append that file's contents to ~/.ssh/authorized_keys:

cat id_rsa.pub >> ~/.ssh/authorized_keys

You can now delete the public key from your server. You should now be able to log into your server without a password using ssh (replace the username lorcan with your own username on the server):

ssh lorcan@example.com
public/sshkeys.txt · Last modified: 2009/01/03 07:03 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki