Setting Up SSH Keys

SSH keys allow you to login to a remote host without a password. To set up ssh keys, follow these steps:

  1. Use ssh-keygen to set up keys for logging in without a password.

    user@host:~$ ssh-keygen -t dsa
    Generating public/private dsa key pair.
    Enter file in which to save the key (/home/user/.ssh/id_dsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/user/.ssh/id_dsa.
    Your public key has been saved in /home/user/.ssh/id_dsa.pub.
    The key fingerprint is:
    6d:e9:f1:da:a5:78:70:af:92:f9:dc:ae:12:9e:51:f4 user@host

  2. Append the contents of id_dsa.pub to the authorized_keys file in your home directory on a remote host. Note that the user names do not need to be the same on the two hosts.

    user@host:~$ scp ~/.ssh/id_dsa.pub remote_user@remote_host:
    user@host:~$ ssh remote_user@remote_host
    remote_user@remote_host:~$ cat id_dsa.pub >> .ssh/authorized_keys
    remote_user@remote_host:~$ rm id_dsa.pub

    The next time you ssh to remote_user@remote_host, you will be logged in without needing to enter a password.

  3. To login from remote_host to host, just run ssh-keygen on remote_host and append the contents of the id_dsa.pub to the authorized_keys file on host.

    Alternatively, to login without a password between multiple (trusted!) hosts, run ssh-keygen on each host. Then append the contents of id_dsa.pub on each host to a single authorized_keys file. Finally, copy the authorized_keys file to the .ssh directory on each host.

No votes yet
Syndicate content