生成密钥对
ssh-keygen -t rsa -b 4096 -C "xxxx@gmail.com" -f /root/.ssh/sshkey -N ""
存放公钥文件到对应位置并授权
cat ~/.ssh/sshkey.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
查看私钥信息复制到本地(SSH客户端所在的设备上)
cat ~/.ssh/sshkey
修改服务器端SSH只接收密钥登录的参数
etc/ssh/sshd_config
PermitRootLogin prohibit-password
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
rm -rf /etc/ssh/sshd_config.d/* /etc/ssh/ssh_config.d/*
重启服务器生效
reboot