2

Linux 主机 ssh 使用公密钥登录仍然需要输入密码解决思路/方法

 2 years ago
source link: https://hellodk.cn/post/539
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux 主机 ssh 使用公密钥登录仍然需要输入密码解决思路/方法

参考上一篇文章: https://hellodk.cn/post/522 ,首先要确保客户端使用 ssh-keygen -t rsa 生成了公钥和密钥,且公钥内容拷贝到了服务器端的 ~/.ssh/authorized_keys

如果上面的检查没有错误,使用 ssh xxx 还是无法登录的话,下面开始检查

  1. 检查 ~/.ssh/authorized_keys 文件权限,确保能被所登录用户读取这个文件的内容
  2. 检查 sshd 的配置

查看 /etc/ssh/sshd_config,检查下面两个项目的设置

# 设置成yes,则代表允许 root 用户登录
PermitRootLogin yes
# 是否让 sshd 去检查用户家目录或相关档案的权限数据
# 这是为了担心使用者将某些重要档案的权限设错,可能会导致一些问题所致
# 例如使用者的 ~.ssh/ 权限设错时,某些特殊情况下会不许用户登入
# 安全性要求不是很高的情况下 建议设为 no,也就是宽松一点的模式
StrictModes no

保存好配置后重启 sshd 服务 systemctl restart sshd

然后在客户端测试

huadekai@huadekaideMBP ~ % ssh xxx
Last login: Tue Apr 27 09:13:29 2021 from 123.123.123.123
[root@sfo2 ~]#

bingo, end.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK