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 firstname.lastname@example.org 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 email@example.com 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. firstname.lastname@example.org'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 email@example.com ‘cat >> .ssh/authorized_keys’ firstname.lastname@example.org’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 email@example.com “chmod 700 .ssh; chmod 640 .ssh/authorized_keys” firstname.lastname@example.org’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 email@example.com [firstname.lastname@example.org /]$ [SSH prompt on email@example.com]
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 firstname.lastname@example.org:/home/asiface testfile 100% 5 0.0KB/s 00:00 [testfile transferred]