/ tutorial

SSH login without password

If you use SSH from the shell often you might be getting tired of entering your password over and over again. If you often log on to other machines from your machine via SSH, be it work, school, or just other machines on your LAN? Then this can be a real time saver. Doing this is also a must if you want to mount remote file systems via SSHFS boot time. Warning! Only do this on machines you trust. If you are on a public machine, it’s probably a good idea to not do this.

Authors Note:

Note on security

Please note that the method in this article does not reflect a good security policy, and can be seen as outdated. For your own security please do not use passwordless keys, but rather give your key a passphrase, and use ssh-agent to avoid having to enter the passphrase each time you use ssh. The rest of this tutorial is still valid.

What are we doing?

We want to make it possible for user-A on host-A to log on to user-Bs account on host-B via SSH without entering a password.

Article continues after ad

How do we do it?

First you log on as user-A on host-A and generate a pair of authentication keys. This step should only be done once, even if you are planning on making remote logon without password possible on several other hosts (host-C, host-D, etc). When prompted for a passphrase, just hit the enter-key. In other words we are not using the passphrase. When prompted for a filename, just hit the enter-key to use the default file.

user-A@host-A:~> ssh-keygen -t rsa
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/user-A/.ssh/id_rsa): 
Created directory '/home/user-A/.ssh'. 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user-A/.ssh/id_rsa. 
Your public key has been saved in /home/user-A/.ssh/id_rsa.pub. 
The key fingerprint is: 3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 user-A@host-A

Now use SSH to create a directory ~/.ssh as user-B on host-B. (The directory might already exist, which is fine, this command will not overwrite the existing directory)

user-A@host-A: ~> ssh user-B@host-B mkdir -p .ssh
user-B@host-B’s password:

The last step is to append user-As new public key to userBs authorized_keys file.

user-A@host-A: ~> cat .ssh/id_rsa.pub | ssh user-B@host-B ‘cat >> .ssh/authorized_keys’ 
user-B@host-B’s password:

Now you should be able to log on to host-B as user-B without having to enter a password.

user-A@host-A: ~> ssh user-B@host-B

To be able to log on to other hosts (host-C, host-D, etc.) in the same way, just repeat the create directory and append public key steps for host-C, host-D, etc.

Photo by Collin Armstrong / Unsplash