How to set SSH password free login on the server of CentOS system


As a system administrator, you plan to use openssh on Linux to automate daily tasks, such as file transfer, backup database dump files to another server, etc. To achieve this, you need to be able to automatically log in from host a to host B. Automatic login, that is, to use SSH in a shell script without entering any password.

This article will show you how to set up SSH password free login on CentOS / RHEL. After automatic login is configured, you can use SSH (secure shell) and secure replication (SCP) to move files.

SSH is open source and the most reliable network protocol for remote login. System administrators use it to execute commands and transfer files to another computer over the network via SCP protocol.

By configuring SSH password free login, you can enjoy the following convenience:

Use script to realize the automation of daily work.
Enhance the security of Linux server. This is a recommended method to prevent the virtual private server (VPS) from brute force attack. SSH key can hardly be broken by brute force attack alone.

What is SSH keygen

SSH keygen is a tool for generating, creating and managing public and private keys for SSH authentication. Through the SSH keygen command, users can create keys that support ssh1 and SSH2 protocols. SSH keygen creates an RSA key for the ssh1 protocol, and SSH2 can be RSA or DSA.

What is SSH copy ID

SSH copy ID is used to copy the local public key to the remote authorized_ Keys file, which also appends the identity file to ~ /. SSH / authorized of the remote machine_ Key file, and give the user home directory of the remote host with appropriate permissions.

SSH key

SSH key provides a better and secure mechanism for logging in to Linux server. After running SSH keygen, a public-private key pair will be generated. You can place the public key on any server and use it to unlock it when connecting to the server from a client with a private key. When the two match, the system can be unlocked without a password.

Setting password free login SSH on CentOS and RHEL

The following steps were tested on CentOS 5 / 6 / 7, RHEL 5 / 6 / 7, and Oracle Linux 6 / 7.

Node 1: node 2: 192.168.l.10

Step 1:

Test connection and access from node 1 to node 2:

Copy code

The code is as follows:

[[email protected] ~]# ssh [email protected]
The authenticity of host ‘ (’ can’t be established.
RSA key fingerprint is 6d:8f:63:9b:3b:63:e1:72:b3:06:a4:e4:f4:37:21:42.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘’ (RSA) to the list of known hosts.
[email protected]’s password:
Last login: Thu Dec 10 22:04:55 2015 from
[[email protected] ~]#

Step 2:

Use the SSH key Gen command to generate the public key and private key. Here, it should be noted that the private key can be encrypted to enhance the security.
Step 3:

Copy code

The code is as follows:

[[email protected] ~]# 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:
b4:51:7e:1e:52:61:cd:fb:b2:98:4b:ad:a1:8b:31:6d [email protected]
The key’s randomart image is:
+–[ RSA 2048]—-+
| . ++ |
| o o o |
| o o o . |
| . o + .. |
| S . . |
| . .. .|
| o E oo.o |
| = ooo. |
| . o.o. |

Use the SSH copy ID command to copy or upload the public key to the remote host, and append the identity file to ~ /. SSH / authorized of node 2_ In keys:

Copy code

The code is as follows:

[[email protected] ~]# ssh-copy-id -i ~/.ssh/
[email protected]’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.

Step 4:

Verify password free SSH login node 2:

Copy code

The code is as follows:

[[email protected] ~]# ssh [email protected]
Last login: Sun Dec 13 14:03:20 2015 from www.ehowstuff.local

I hope this article can help you and provide you with basic knowledge and quick guide to SSH password free login to CentOS / RHEL.