In the following example, ssky-keygen and SSH-copy-ID can be used to log on to a remote Linux host without a password.
Ssh-keygen creates the public key and key.
Ssh-copy-ID copies the public key of the local host to the authorized_keys file of the remote host.
The SSH-copy-ID will also be sent to the user home directory (home) and ~ of the remote host ~ /. Ssh, and ~ /. Ssh/authorized_keys.
Step 1: Use SSH-key-Gen to create a public key and a key on the local host
[Email protected] $ 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
[Email protected]
Step 2: Use SSH-copy-ID to copy the public key to the remote host.
[Email protected] $ ssh-copy-ID-I ~ /. Ssh/id_rsa.pub [email protected]
[Email protected]'s password:
Now try logging into the machine, with-ssh? Remote-host '', and check in:
. Ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
[Note: The Ssh-copy-ID appends the key to. Ssh/authorized_key of the remote host.]
Step 3: log on to the remote host directly
[Email protected] $ SSH remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH does not ask for the password.]
[Email protected] $
[Note: You have logged on to the remote host]
Set an SSH alias and log on without a password