1. 返回错误信息

SSH服务器拒绝了用户密钥。请尝试其它用户密钥或者其它身份验证方法…
所选的用户密钥未在远程主机上注册。请再试一次…

(tmd)我Ubuntu能连接,为何这个Centos不行

2.解决问题

2.1 方法一(知乎老哥扯皮,搞半天也没成功,我是失败了,你可以试试)

**

  1. #修改selinux的配置文件
  2. [root@localhost ~]# vim /etc/selinux/config
  3. SELINUX=enforcing #注释这行
  4. SELINUXTYPE=targeted #注释这行
  5. SELINUX=disabled #新增这行
  6. #之后需要重新启动服务器
  7. [root@localhost ~]# reboot
  8. [root@localhost ~]# /usr/sbin/sestatus -v #查看selinux的状态命令
  9. SELinux status: disabled
  10. # 关闭防火墙
  11. [root@localhost ~]# sudo -i
  12. [root@localhost ~]# iptables -F #清空防火墙配置
  13. [root@localhost ~]# /etc/init.d/iptables save #清空防火墙配置后,记得保存

2.2 解决了我的问题,我是centos系统

  1. # 开启ssh远程登录
  2. [root@localhost ~]# vim /etc/ssh/sshd_config
  3. # 然后在无光标状态下 /PermitRootLogin 搜索
  4. PermitRootLogin yes # 默认为no,需要开启root用户访问改为yes

:wq 保存退出,重启ssh

  1. systemctl restart sshd

image.png

欧克

3. SELINUX是啥

SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统

SELinux共有3个状态

  • enforcing (执行中)
  • permissive (不执行但产生警告)
  • disabled(关闭)


4.ssh -i key 执行时 Permissions 0644 for ‘你的.pem’ are too open 问题

  1. // 解决办法
  2. chmod 600 你的密钥文件
  3. // 比如: chmod 600 ekko.pem

参考文献


https://blog.csdn.net/l18637220680/article/details/70231989
https://www.zhihu.com/question/35291523/answer/205691737