Get the App
SLTechnology News&Howtos  ›  Network Security  › 

SSH password-free login configuration operation

Shulou Source: shulou.com Published: 2022-06-01 08:19:09 09月30日 Update

I) generate public and private keys locally

1) [root@SamuluIndex ~] # cd .ssh

2) [root@SamuluIndex .ssh] # rm-f * (clear all old files in the .ssh directory)

3) [root@SamuluIndex .ssh] # ssh-keygen. Press enter in three places that need to be entered in the process.

Id_rsa and id_rsa.pub are generated in the .ssh directory. Where id_rsa is the private key, which is used by the local machine, and id_rsa.pub is the public key, which is used by other machines.

(2) upload the public key to the remote host

[root@SamuluIndex .ssh] # scp id_rsa.pub root@172.20.0.141:/root/.ssh

After you are prompted to enter the password for the remote host (172.20.0.141), you can see the prompt for a successful upload:

Id_rsa.pub 100% 398 0.4KB/s 00:00

(3) Log in to the remote host and write the client public key to the authorized_keys file

[root@SamuluIndex .ssh] # ssh 172.20.0.141

Warning: Permanently added '172.20.0.141' (RSA) to the list of known hosts.

Root@172.20.0.141's password:

Last login: Tue Apr 29 21:09:27 2014 from 192.168.0.56

[root@tixa ~] # cd .ssh

[root@tixa .ssh] # cat id_rsa.pub > > authorized_keys

At this point, you can see two files, authorized_keys and id_rsa.pub, in the .ssh directory of the 141machine. The main purpose of id_rsa.pub is to write public key information into authorized_keys. Then delete the id_rsa.pub from both hosts, otherwise the machine will not be able to log in to other machines without a password.

(4) exit the remote host and log in to the remote host again

At this point, it is found that you can log in to remote machine 141 without a password on 100 machines.

And two files are kept in .ssh on the100th machine: id_rsa and known_hosts, and one file in .ssh on the141machine: authorized_keys.

Tags: Machine host public key file login password directory two native prompt generation input success three no information available in enter key place customer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Linux MariaDB Shulou Information