1. Locally generated key
# enter the SSH

cd ~/.ssh

# generate key

ssh-keygen

# copy public key to server (XXX is your server IP address)

scp id_rsa.pub root@xxx:/root/.ssh

Copy the code

2. Client operations — Modify the. SSH /config file on the local PC

vi ~/.ssh/config



# add the following content (XXX is your server IP address) :

Host testWeb The name/alias of the remote host

HostName xxx.xxx.xxx.xxx  # Remote host IP address

User root # login user name

Copy the code
  1. The server
cd ~/.ssh

Add id_ras.pub to the end of authorized_keys

cat id_rsa.pub >> authorized_keys

Copy the code
  1. Restarting the SSH Service
Restart the SSH service

systemctl restart sshd

# exit server

exit

# Try again, you can avoid login hunger

ssh [email protected]

Copy the code