This tutorial answers your question i.e. how to setup Passwordless SSH? SSH  is a protocol to communicate a server with the client in an encrypted manner.

It has replaced telnet protocol, which was not at all secure at all. Almost all the Linux system admins know about it because they use it to connect to Linux servers as the physical access to the server is very limited.

SSH is installed by default on most Linux distribution. & to access a server through ssh is very easy, you use the following command,

$ ssh {Server IP address or FQDN}

and then you enter the credentials. But in this tutorial, we will learn to access ssh sessions securely with the help of Public/Private keys authentication aka passwordless ssh setup. Advantages of using Public/Private keys authentication are

  • You won’t be asked for a password every time you access the server (unless you are using a passphrase to decrypt the keys)
  • No one can gain unauthorized access to your server unless they have the right key.

Now let’s create Public/Private keys for passwordless ssh setup to access our servers.

Recommended Read: Simple guide to install SSH on Ubuntu

Also Read: How to use SSH command with password in a single line

You can also see this video tutorial here for the complete Password less ssh setup,


Setup Password-less SSH in Linux

Creating keys on the Local machine

Remember this, keys are to be created on each host that you wish to gain access from. So if there are 10-20 hosts from where you want to access a server, we must create keys on all those 10-20 servers.

To create keys, run the following command,

$ ssh-keygen –t rsa

It will then ask you to select a location for the generated keys. By default, the keys will be stored in the ~/.ssh which is a hidden directory in your home folder (/home/dan/.ssh). The private key will be called id_rsa and the associated public key will be called

It will also ask you to enter a passphrase, which is used to decrypt the keys. If you don’t wish to use any pass-phrase just leave it empty & press enter or else provide a pass-phrase.

Next, set permissions on your private keys,

$ chmod 700 ~/.ssh

$ chmod 600 ~/.ssh/id_rsa

Configuration on Remote Server

Now copy the Public key ( & move it to the remote server at /home/user/.ssh/authorized_keys folder. Now that the public keys have imported to server, remove them from local machine.

Next, we will also have to set permissions on the server as well,

$ chmod 700 ~/.ssh

$ chmod 600 ~/.ssh/authorized_keys

All the settings for Public/Private keys authentication are now complete.

Testing the Public/Private keys authentication  

Now log back into the local machine to access the server & enter,

$ ssh {Server IP address or FQDN}

& hit enter. You will notice that you won’t be asked for the credentials & are logged directly into the server.

Remove password-based authentication

Once you have tested your passwordless ssh setup, you can also disable the use of password authentication so that everyone uses only keys to access the server. Thus making your servers more secure. To disable password authentication , open /etc/sshd/sshd_config & change the following parameter, 

PasswordAuthentication no

That’s it, this completes our tutorial on how to set up Passwordless SSH on Linux machines.

I also recommend reading “Ultimate Guide to Securing SSH Sessions” to implement some other measure to secure your servers. If you have any comments/queries, please mention them in the comment box down below.

We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,

DigitalOcean - 100$ free credit & Linode - 100$ free credit

Check some Exclusive Deals, HERE.

Also, check out DevOps Book You should read section.