Using the ssky-keygen and ssh-copy-id examples below, you can log in to a remote Linux host without entering a password in three easy steps.
Ssh-keygen Creates a public key and a key.
Ssh-copy-id Copies the local host's public key to the remote host's authorized_keys file.
Ssh-copy-id also sets the appropriate permissions for the remote host's home directory (home) and ~ / .ssh, and ~ / .ssh / authorized_keys.
Step 1: Use ssh-key-gen to create public keys and keys on the local host
Linuxidc @ local-host $ ssh-keygen -t rsa
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is: 33: b3: fe: af: 95: 95: 18: 11: 31: d5: de: 96: 2f: f2: 35: f9
Linuxidc @ local-host
Step 2: Use ssh-copy-id to copy the public key to the remote host
Linuxidc @ local-host $ ssh-copy-id -i ~ / .ssh / id_rsa.pub email@example.com
Linuxidc @ remote-host's password:
Now try logging into the machine, with -ssh? Remote-host', and check in:
.ssh / authorized_keys to make sure we have not added extra keys that you were not expecting.
[Note: ssh-copy-id appends the key to the remote host's .ssh / authorized_key.]
Linuxidc @ local-host $ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
Linuxidc @ remote-host $
[Note: You are now logged on to the remote host]