CentOS set ssh key login original

1. Generate a key pair (two ways) and configure##

Method 1: Use ssh-keygen(1) to generate and configure

(1) Generate a key pair

[ root@iZwz9catu2mrq92b07d1d0Z ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.//Enter file name
Enter file in which to save the key(/root/.ssh/id_rsa): keys_root   
//Enter the private key encryption password
Enter passphrase(empty for no passphrase)://Enter the password again
Enter same passphrase again:                            
              
Your identification has been saved in keys_root.
Your public key has been saved in keys_root.pub.
The key fingerprint is:
f4:f9:70:51:cf:09:f6:da:30:6a:b1:67:4f:dc:14:44 root@iZwz9catu2mrq92b07d1d0Z
The key's randomart image is:+--[ RSA 2048]----+|             o+E ||..ooo||...o o+||...+.*..||        S ++.++.||.+o o  ||..|||||+-----------------+//The file is generated successfully, keys_root is the private key, keys_root.pub is the public key[root@iZwz9catu2mrq92b07d1d0Z ~]# ls
keys_root  keys_root.pub

(2) Configure the public key

//Write the generated public key to the user's authorized_keys[root@iZwz9catu2mrq92b07d1d0Z ~]# echo -e '#this is keys_root'>>~/.ssh/authorized_keys ; cat ~/keys_root.pub >> ~/.ssh/authorized_keys   

[ root@iZwz9catu2mrq92b07d1d0Z ~]# cat ~/.ssh/authorized_keys
# this is keys_root
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyhp9SBxas8Nmwdi4dQfOuUULpMGRnGEFopU2DXhSF+PE/s80xrVS31Ycd5o4gU3iehKx2vo4OEB2lYZ2JCfptTc59HAj+Qwqh7i5S4YQuX/+31GkY+s8XKFR4QgH1ubQt9feU2cagfG1f+wWRsa0YtefE67Kjv6OZuKuA2bOdrAH4mzV1m71iLMUZYgaEnfJExXj2lbPAXRqCV+tdIj9h0jxhB5pQXsZ3NE38D22WYNKO4Sy8odfE7Oby1I0Emm8Uhiwqgx91HP22iY/WqzZOxeKZPF17CPWr9cChaPh9/DXM1Wd8KDCg33MO6hbpqAwh7iEughndXly0FY0oZNKnQ== root@iZwz9catu2mrq92b07d1d0Z

(3) Configure the private key

  1. Download the private key to the local machine
    [ root@iZwz9catu2mrq92b07d1d0Z ~]# sz keys_root

  2. Start Xshell

  3. Tools

  4. User Key Manager

  5. Import the downloaded keys_root file (Import)

  6. Configuration complete

Method 2: Use Xshell to generate and configure

  1. Start Xshell
  2. tool
  3. New User Key Wizard (New User Key Wizard)
  4. Choose next step by step
  5. After entering the key name and private key password, select Next
  6. The key pair is generated successfully. At this time, the private key has been automatically imported into Xshell. We need to manually save the public key to the local machine.
  7. Upload the saved public key file to the server and configure it in the user's authorized_keys file

Two, log in to the server by key##

  1. Create a new session, fill in the name, host and other information
  2. Select user authentication in the left column, select Public Key as the method on the right, fill in the user name, select the corresponding user key and fill in the key password, and click OK
  3. Connection session

appendix##

[ root@iZwz9catu2mrq92b07d1d0Z ~]# man ssh
  1. ssh-keygen command introduction

The user creates his/her key pair by running ssh-keygen(1). This stores the private key in ~/.ssh/identity (protocol 1), ~/.ssh/id_dsa (protocol 2 DSA), ~/.ssh/id_ecdsa (protocol 2

ECDSA), or ~/.ssh/id_rsa (protocol 2 RSA) and stores the public key in ~/.ssh/identity.pub (protocol 1), ~/.ssh/id_dsa.pub (protocol 2 DSA), ~/.ssh/id_ecdsa.pub (protocol 2 ECDSA), or

~ /.ssh/id_rsa.pub (protocol 2 RSA) in the user’s home directory. The user should then  copy the public key to ~/.ssh/authorized_keys in his/her home directory on the remote machine.

The authorized_keys file corresponds to the conventional ~/.rhosts file, and has  one key per line, though the lines can be very long. After this, the user can log in without giving

the password.

Note: Each user has his own authorized_keys

  1. Authorized_keys file introduction

~ /.ssh/authorized_keys

Lists the public keys (RSA/ECDSA/DSA) that can be used for logging in as this user. The format of this file is

described in the sshd(8) manual page. This file is not highly sensitive, but the recommended permissions are

read/write for the user, and not accessible by others.

Note: It is recommended that the file permissions are read and write permissions for the owner, and other users have no permissions

This article from the Chinese CentOS station - focus on Linux technology Author: [centos] (https://www.centoschina.cn/author/1) published its copyright are CentOS Chinese station - all focused on Linux technology, the content of the article the authors and do not necessarily represent CentOS Chinese station - focus on Linux technology point of view Agree or support. If you need to reprint, please indicate the source of the article.

( adsbygoogle = window.adsbygoogle || []).push({});

Recommended Posts

CentOS set ssh key login original
CentOS 7 set up NTP, SSH service
How to set up SSH keys on CentOS 8
Centos7 install docker-18.x original
Centos7 install pyenv original
CentOS 7 install Redis 5.0.8 original
Centos7.2 system optimization original
Centos 7 install Zabbix 3.4 original
Centos7 set up GitBook environment
CentOS 7 user account configuration original
Centos6 set up GitBook environment
RHEL CentOS 8 SSH two-factor authentication
centos6.9 rabbitmq set up SSL
CENTOS7 manually install CEPH original
Set static IP under Centos