Passwordless SSH login


  1. Ensure proper configuration
  2. Generating a public/private key pair
  3. Putting the key on the server
  4. Done!
  5. One caveat

Hate typing your SSH password every time you need to login remotely to your machine? Set up public key authentication, and you can securely login without ever having to type a password.

For this guide, let's say I have two machines, a laptop and a desktop. I move around a lot with my laptop (SSH client), and frequently need to access files or run commands on my desktop (SSH server) but hate typing the password to connect each time.

Ensure proper configuration

I am assuming you are using OpenSSH and that you're already able to login remotely using a password. If not, usually all you have to do is install openssh-server on the server and openssh-client on the client. You might also have to open up TCP port 22 on the server if that's not done for you.

Pretty much all modern distros (certainly all the popular ones) will have pubkey authentication enabled in the SSH configuration. On the server, it's enabled as long as you do NOT see this line in /etc/ssh/sshd_config:

PubkeyAuthentication no

Often you will see the PubkeyAuthentication line commented out or not present at all. This is fine, since it defaults to yes.

On the client, pubkey authentication is enabled as long as that line appears in neither /etc/ssh/ssh_config nor ~/.ssh/config.

Generating a public/private key pair

To begin setting up public key authentication, you'll need to first generate public and private keys on the client. Generating a key pair is simple. Just run ssh-keygen and push enter a lot to accept the defaults:

[icydog@client ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/icydog/.ssh/id_rsa):
Created directory '/home/icydog/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/icydog/.ssh/id_rsa.
Your public key has been saved in /home/icydog/.ssh/
The key fingerprint is:

Now, in ~/.ssh/, you'll have two files. id_rsa is the private key, which you must keep secret. is the public key, which we're going to copy to the server. It is safe to share the public key with anyone, including adversaries.

Putting the key on the server

Now we need to copy the public key to the server and add it to the list of authorized keys. First, scp the key to the server:

[icydog@client ~]$ scp ~/.ssh/'s password:                                    100%  393     0.4KB/s   00:00

Next, log on to the server and append the public key to the server's authorized_keys file:

[icydog@client ~]$ ssh's password:
Last login: Mon Dec  3 16:04:12 from
[icydog@server ~]$ cat >> ~/.ssh/authorized_keys
[icydog@server ~]$ rm


Now if you try to make an SSH connection, the server will have the client's public key and the client will have its private key, and magic will happen. You should not be prompted for a password any more:

[icydog@client ~]$ ssh
Last login: Mon Dec  3 16:08:55 2007 from
[icydog@server ~]$

ssh, scp, sftp, and any GUI tools built on top of these (like KDE's fish KIOslave) will no longer prompt for a password.

One caveat

I want to point out one more thing. The most common cause for SSH public key authentication mysteriously not working is incorrect file permissions on the ~/.ssh/ files. As a general rule, your file permissions (on both machines) should be at least as restrictive as:

~/.ssh/                      rwx------ (700)
~/.ssh/authorized_keys       rw-r--r-- (644)
~/.ssh/id_rsa                rw------- (600)
~/.ssh/            rw-r--r-- (644)