SSH public and private key configuration (SSH password-free login)

 

1. First log in to Linux with user A who wants to initiate ssh password-free access (referred to as client Linux)

2. Enter the home directory (cd ~) to see if there is a .ssh folder (in linux, folders starting with . are hidden, use ll -a to view), if not, create (mkdir ~/.ssh), and Modify access permissions (chmod 700 ~/.ssh);

3. Generate public and private keys, command: ssh-keygen -t rsa . Go all the way to enter, you will be prompted to enter passphrase in the middle, this is the encrypted password for the private key, to prevent others from logging in to your user and seeing your private key. After the command is executed, two files, id_rsa (private key) and id_rsa.pub (public key), will be generated in the .ssh directory. The length of the generated key is 2048 bits by default.

-------------------------

4. Enter the home directory where the Linux server of user B who wants to log in through ssh without password is located (referred to as server-side Linux)

5. Send and copy the public key in step 3 to the .ssh directory and rename it to authorized_keys   

(There are many methods, such as using scp id_rsa.pub user B@IP address or domain name: /home/.ssh/authorized_keys)

6. Then you can test whether the configuration is successful, execute on user A: ssh user B@IP address or domain name

(ssh specified port number command format: ssh -p port number user@IP address or domain name)

 

Reference: https://blog.csdn.net/mchdba/article/details/52193812

 

Principle: Asymmetric encryption, the public key is used to encrypt, and the private key is used to decrypt

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325207093&siteId=291194637