系统秘钥登录
查看系统日志
cat /var/log/secure
1.生成一对rsa秘钥
ssh-keygen
Generating public/private rsa key pair.#生成公钥和秘钥
Enter file in which to save the key (/root/.ssh/id_rsa);#保存的位置
Enter passphrase (empty for no passphrase):#给秘钥设置密码
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:uPJTaDVz1fu2YxDUjMvQoEx1mEQTLNzyjY1fZ3ZRHCw root@iZ8vb5bk6d9av06eo7b2lsZ
The key's randomart image is:
+---[RSA 2048]----+
| ..*B*o=o+|
| o+.*+E.=.|
| o+.O o..|
| .+ .+ *..=|
| .oS+ . o+o|
| o.. o o|
| .... ...|
| o. + |
| .. . .|
+----[SHA256]-----+
2.将公钥添加到liunx系统中
cd /root/.ssh/
ls
id_rsa私钥(注意保存) id_rsa.pub公钥
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
3.将秘钥下载并删除
rm -rf ~/.ssh/id_rsa* #删除公钥和私钥文件
4.修改ssh服务器配置,启用公钥
vim /etc/ssh/sshd_config
#在文末添加 都在末尾
PubkeyAuthentication yes
passwordAuthenticat配置项 yes改为no
systemctl restart sshd #重启