Linux Pathfinder: Linux Howtos and Tutorials

How to Configure SSH and SCP Without Prompting Password

How to Configure SSH and SCP Without Prompting Password
Configure SSH and SCP Without Prompting Password

Secure SHELL is the most trusted network protocol. SSH is used to login from local linux servers to remote servers. Secure Copy (SCP) Protocol is also used to transfer files from local to remote servers.

In this tutorial we will describe how to configure ssh and scp without prompting password. There are simple settings to SSH association between your local server and the remote server. Without prompting password with SSH increase the trust between two servers for easy file sync or transfer.

Here, we will setup SSH without entering password automatic login from server 172.16.0.3 as user linuxpathfinder to 172.16.0.4 with user asiface.

Create Authentication SSH-Keygen Keys on (172.16.0.3)

First of all you will login into server 172.16.0.3 with user linuxpathfinder and generate a pair of public keys as shown below.

$ ssh-keygen -t rsa

Generating public/private rsa key pair.
 Enter file in which to save the key (/home/linuxpathfinder/.ssh/id_rsa): [Press enter key]
 Enter passphrase (empty for no passphrase): [Press enter key]
 Enter same passphrase again: [Press enter key]
 Your identification has been saved in /home/linuxpathfinder/.ssh/id_rsa.
 Your public key has been saved in /home/linuxpathfinder/.ssh/id_rsa.pub.
 The key fingerprint is:
 35:00:a6:9c:e3:34:ce:65:bf:e2:54:5c:a8:83:a0:5e linuxpathfinder@linuxpathfinder.com
 The key's randomart image is:
 +--[ RSA 2048]----+
 |      o..        |
 |   . +   o       |
 |  . B o . +      |
 | . * * + o .     |
 |.  E= o S        |
 |. .    o .       |
 | .    o .        |
 |     o .         |
 |      .          |
 +-----------------+

Create .ssh Directory on (172.16.0.4)

Use SSH (Secure Shell) command from server 172.16.0.3 to connect server 172.16.0.4 using username asiface and create .ssh directory under it as shown below.

$ ssh asiface@172.16.0.4 mkdir -p .ssh

The authenticity of host '172.16.0.4 (172.16.0.4)' can't be established.
 RSA key fingerprint is c7:53:83:43:b3:cf:d8:e2:b0:0d:50:7b:13:32:29:3d.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added '172.16.0.4' (RSA) to the list of known hosts.
 asiface@172.16.0.4's password: [Enter Your Password Here]

Upload Generated Public Keys to (172.16.0.4)

Use Secure Shell command from server 172.16.0.3 and upload newly generated public key (id_rsa.pub) on server 172.16.0.4 under asiface’s .ssh directory as a file name authorized_keys.

$ cat .ssh/id_rsa.pub | ssh asiface@172.16.0.4 ‘cat >> .ssh/authorized_keys’

asiface@172.16.0.4’s password: [Enter Your Password Here]

Set Permissions on (172.16.0.4)

Note that depending on your different version of Secure Shell on servers, we might also have to set the permissons on .ssh directory and authorized_keys file.

Set the permissions of (.ssh) to 700
Set the permissions of (.ssh/authorized_keys) to 640

$ ssh asiface@172.16.0.4 “chmod 700 .ssh; chmod 640 .ssh/authorized_keys”

asiface@172.16.0.4’s password: [Enter Your Password Here]

Login from 172.16.0.3 to 172.16.0.4 Server without Password

From now on you can log into 172.16.0.4 as asiface user from server 172.16.0.3 as linuxpathfinder user without password:

$ ssh asiface@172.16.0.4

[asiface@linuxtest.com /]$ [SSH prompt on asiface@172.16.0.4]

The procedure to setup SSH association between 172.16.0.3 and 172.16.0.4 is completed.

Transfer a File/Folder Without Entering Password

From now onwards you will also be able to transfer a file/folder from 172.16.0.3 to the 172.16.0.4 without entering any password.

$ scp testfile asiface@172.16.0.4:/home/asiface

testfile           100%    5     0.0KB/s   00:00 [testfile transferred]

 

Share this article:

Asif Khan's picture
I am an experienced Linux System and Network Administrator with having more than 6 years of experience. My primary responsibilities are to keep up and running Linux system environment, backups important data with scripting and configuration management on AWS Linux server environments. My aim is to help people, in finding their path towards a solution to their problems. Well, I believe helping others can good for both parties, to them and to you as well. That day and today is the day that thousands of people seek help from my website to help people find answers to their questions. I am sure that everyone will get all the answers to their questions related to software and operating system, and this website will help you keep your system updated.

Add new comment

Image CAPTCHA

Enter the characters shown in the image.