SSH密钥登陆

2018年4月12日 Linux 0条评论 阅读次数 515

制作SSH登陆密钥

[root@host ~]$ 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:Zvw1Y2cKbeY50Y2C92Quxn9s/G+jK0liXnGjL7x/qEw
root@TeachingVPS
The key's randomart image is:

安装密钥

[root@host ~]$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys

确保权限

[root@host ~] chmod 600 ~/.ssh/authorized_keys [root@host ~] chmod 700 ~/.ssh

修改sshd_config

[root@host ~]$ vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes

关闭密码登陆

PasswordAuthentication no