In a Data-center where we have many Linux servers, it becomes very cumbersome and a tedious job to connect every server with a password for performing checks and running sript. To ease the task, the administrator can make a passwordless connection from 1 server with many servers. In this article, you are going to learn how to SSH between two Linux servers with passwordless methods.

Here we will connect Remote server from a local server via SSH without the need of entering the password.

1) Please check here, when we are trying to connect Remote Server ( from a Local server (, it asks for a password. Only when we enter correct password then it allows connecting to it.
[root@Localhost]# ssh root@
root@'s password:
2) Now please follow the steps below to make it passwordless. First, we will run “ssh-keygen” command in Local Server to generate Public Key & Private Key. Public key is stored in “/root/.ssh/” file, and private key is stored in “/root/.ssh/id_rsa” file.

Recommended Article: 5 Simple Steps to Recover Root Password of the Linux Server

[root@Localhost]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
ce:82:d2:47:2f:94:45:8b:20:13:09:26:8c:ba:d0:bf root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|=o+o. . |
|+..o . o . |
|.. . o |
|o . o |
|.. . + S |
|. ..+ + |
| . o.+ + |
| .E. o |
| |
3) Below files are generated in Local Server after running the above command.
[root@Localhost]# cd /root/.ssh
[root@Localhost]# ls -ltr
-rw-r--r--. 1 root root 394 Oct 28 00:44
-rw-r--r--. 1 root root 389 Oct 28 00:45 known_hosts
-rw-------. 1 root root 1675 Oct 28 02:12 id_rsa

“id_rsa” is a private key and have (-rw——-) access to the root user only.Hence it cannot be accessed by any group users & others.
“” is a public key and have (-rw-r–r–.) permission. Hence it can be accessed by the root user, any group user & others.

4) Copy public key from Local Server to the Remote Server, and save the file with the name “authorized.key” file.

This can be done by two methods.

  • By using ssh-copy-id command. It appends the public key to the “authorized_keys” file in the Remote server.
[root@Localhost]# ssh-copy-id -i ~/.ssh/
root@'s password:
Now try logging into the machine, with "ssh ''", and check in:
to make sure we haven't added extra keys that you weren't expecting.
  • The other method is to transfer the “” file to the Remote server with name “authorized_keys”.
[root@Localhost]# scp /root/.ssh/
root@'s password: 100% 394 0.4KB/s 00:00
5) Now when you will log in to the Remote server via SSH from Local server, it will be connected without asking for password.
[root@Localhost]# ssh root@
Last login: Fri Oct 27 22:37:12 2017 from
[root@localhost ~]#

Now you are ready to connect secured passwordless connection between Local Server and Remote Server.
Please leave your comments and feedback in the comment box if you find it beneficial or in case of any doubts.

Leave a Reply

1 Comment on "How to Connect Two Linux Servers Without Password via SSH"

newest oldest most voted
Notify of

This is a huge security risk. You should NEVER allow root login via SSH. If anything, set up a standard user with SSH Key Authentication (which is what this is, the title of this article isn’t a good one) and then sudo as needed.

At the very least, alert your readers that SSH login as root is a security risk.