How To Do Password Less SSH/SCP between Linux Servers

Recently for a POC purpose, there was a need of establishing passwordless secure shell file transfer (SCP) between two Linux servers for automated scripts to work. It wasted my couple of hours, so I decided to pen it down in the blog.

Step 1:
(*note server1 is the source server and server2 will be the destination server and user is root in this case)

Login into server1, you will land in the following directory /root. Perform ‘ls -a’ and see if any ‘.ssh’ directory is available. If not present, create one:

server1# mkdir ~/.ssh

Step 2:

server1# cd .ssh

Step 3:

server1# ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in
The key fingerprint is:
39:13:dc:c1:47:69:23:3d:e1:ea:ec:12:aa:ab:74:a3 root@server1

Step 4:

Copy the ‘’ file to server2 in .ssh directory within file system /root.

server1# scp /root/.ssh/ root@server2:/root/.ssh/local_copy/

The direct scp will not work still now and will ask for server2 login password. So transport the file via WinSCP or any other method.

If that is also giving you an issue, copy the content of the file from server1 and paste it to newly created file in server2.

Step 5:

Go to server2 /root/.ssh. Append the RSA fingerprint of server1 to server2 Authorization Key:

server2# cat >> .ssh/authorized_keys

Step 6:

Now the connection between server1 and server2 is passwordless

For example:

[root@server1]# scp -p test_file.txt server2:/root

*Note repeat steps 1-6 for all target servers you would like passwordless access from server1

* FYI Ensure your /home/user directory has the permission 755 also


About Swapratim

Blog Writer in Medium for Chatbots Magazine - world's biggest chatbot magazine. Also he writes in Bot Publication and Chatbots Journal on regular basis ( Experienced in IT development & support pursuing different roles & responsibilities. He has worked on several innovative projects. Apart from this, he likes to share his learning with everyone which he had learned over years. Sole purpose of this blog is to share the author's knowledge in IT, passion for travel and recent trends with you. Hope you will enjoy his contents.
Aside | This entry was posted in Various Scripting Tutorials. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s