SSH password-free login remote server on Linux

Source: Internet
Author: User
Tags scp command

When you use SSH to log in to a remote server, you need to use the input password, hoping that you can implement a key login and exempt from entering the password, so you can be ready to implement the batch automatic deployment host later.

环境如下:
IP Address Operating System
Server-side 10.0.0.10 CentOS 6.5 x86
Client 10.0.0.61 CentOS 6.5 x86

1. Client-generated key pair

[[email protected] ~]# ssh-keygen -t rsa
Generating public/private RSA key pair.
Enter file in which to save the key (/ROOT/.SSH/ID_RSA):
Created directory '/root/.ssh '.
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/id_rsa.pub.
The key fingerprint is:
99:AF:26:B0:23:E2:04:9F:48:02:77:8A:D5:6D:B3:C7 [email protected]
The key ' s Randomart image is:
+--[RSA 2048]----+
| |
| . . |
|. o O + |
|. + O. + O |
|+.. . E |
|+o .... |
|.. o O. |
|o. O. .. |
|. O. . O. |
+-----------------+

To view the generated key pair
[[email protected] ~]# ls. ssh/
Id_rsa id_rsa.pub
Id_rsa is a private key, this generally needs to be kept secret; Id_rsa.pub is a public key, this can be public.

2. Upload the public key to the server side

To operate with the SCP command:
[Email protected] ~]# SCP. ssh/id_rsa.pub [Email protected]:/root/
The authenticity of host ' 10.0.0.61 (10.0.0.61) ' can ' t be established.
RSA key fingerprint is 83:C2:2D:85:79:F7:20:36:34:1D:53:1C:7A:B0:D9:BC.
Is you sure want to continue connecting (yes/no)? Yes
warning:permanently added ' 10.0.0.61 ' (RSA) to the list of known hosts.
[email protected] ' s password:
Id_rsa.pub 100% 394 0.4kb/s 00:00

3. Server-side operation
Add the public key from the client to the. Ssh/authorized_keys:

[[email protected] ~]# mkdir. SSH
[email protected] ~]# cat id_rsa.pub >>. Ssh/authorized_keys
[Email protected] ~]# chmod Ssh/authorized_keys

4. Modify the SSH configuration file/etc/ssh/sshd_config, and locate the following line:

Pubkeyauthentication No
Modified to:

Pubkeyauthentication Yes

5. Testing

[[email protected] ~]# ssh [email protected]
Last login:wed-2 13:39:22 2018 from 10.0.0.10
[Email protected] ~]#

6. Precautions

    1. In the server side need to turn selinux off, or finally can not use the key for remote login;
    2. When the client uses the SCP command, it also needs to install the SSH client on the server side, otherwise it can not upload the public key to the server side, or use Ssh-copy-id [email protected] To replace the SCP operation (so that the server side does not need to execute the Create. SSH directory, etc., which is equivalent to the command can help us complete the key upload and configuration work);

SSH password-free login remote server on Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.