SSH密钥登录配置
smartpotato 超膜裁形
本文距离上次更新已过去 0 天,部分内容可能已经过时,请注意甄别。

生成密钥

1
ssh-keygen -t rsa

-t 指定加密算法 rsa dsa

-f 指定文件名

-b 指定二进制密钥位数 1024 2048 4096

1
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.10.103 -p 22
1
chmod 644 ~/.ssh/authorized_keys

创建认证文件

1
2
3
touch .ssh/authorized_keys
chmod 700 .ssh/authorized_keys
cat .ssh/id_rsa.pub >> .ssh/authorized_keys

测试下密钥登录

1
2
3
4
5
6
7
8
# vim /etc/ssh/sshd_config
PasswordAuthentication no //yes改为no 关掉密码登录
ChallengeResponseAuthentication no //yes改为no
RSAAuthentication yes //去掉前面的注释
PubkeyAuthentication yes //去掉前面的注释
AuthorizedKeysFile .ssh/authorized_keys //去掉前面的注释

改完重启sshd生效 systemctl restart sshd
 请作者喝咖啡