Leif160519的blog Leif160519的blog

——————

目录
解决SSH免密钥登录却还是需要密码的问题
/  

解决SSH免密钥登录却还是需要密码的问题

1.问题描述

在使用了ssh-copy-id -i root@192.168.81.12配置免密钥登录之后,发现ssh到机器上还是需要密码

2.解决方案

2.1 查看系统日志,定位问题

执行cat /var/log/secure | grep sshd 查看系统的安全日志,然后再安全日志中看到SSH登录过程中提示了如下错误:
image.png

2.2 解决SSH Authentication Refused问题

从日志中我们已经分析出了错误的具体原因,提示我们 /root 目录的属主和权限配置不当,于是执行以下命令进行更改:

chmod og-w /root

执行完成后,重启SSH服务再次执行ssh 登录时发现已经实现了免密登录,问题解决

3.扩展说明

SSH登录过程如果出现问题除了查看上述 var/log/secure文件外,还可以通过在 ssh 命令后添加调试参数 -vvv来查看调试信息(eg: ssh -vvv 192.168.81.12ssh -v root@192.168.81.12便会以调试模式来执行本次ssh命令),以此来更好的定位问题。

.ssh目录以及改目录下其他文件的权限说明:

.ssh
├── authorized_keys
├── id_rsa
├── id_rsa.pub
└── known_hosts

drwx------   2 root root    80 4月  17 10:01 .ssh
-rw------- 1 root root  807 4月  17 10:00 authorized_keys
-rw------- 1 root root 1675 4月  17 09:59 id_rsa
-rw-r--r-- 1 root root  393 4月  17 09:59 id_rsa.pub
-rw-r--r-- 1 root root  175 4月  17 10:01 known_hosts

权限说明

  • .ssh:700
  • authorized_keys:600
  • id_rsa:600
  • id_rsa.pub:644
  • known_hosts:644

4.参考


“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题解决SSH免密钥登录却还是需要密码的问题
作  者Leif160519
出  处https://github.icu/articles/2020/04/17/1587091253820.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!