zoukankan      html  css  js  c++  java
  • [CentOS7][ssh][publickey][troubleshoot] 通过密钥登录ssh故障排查

    通常情况下,我会使用非对称加密的方式来进行ssh的登录。

    做法:

      将公钥添加到 $HOME/.ssh/authorized_keys 文件中。

    但是通常,会遇见各种各样的问题,导致失败。汇总如下:

    0. 常用的排除手段,一般就是,双端开debug,clinet开启的方式如下,server还从来没与与遇见过需要开的情况,一般开client端就都搞定了。

    /home/tong [tong@T7] [10:05]
    > ssh -vvvvv root@t54
    OpenSSH_7.5p1, OpenSSL 1.1.0e  16 Feb 2017
    debug1: Reading configuration data /home/tong/.ssh/config
    debug1: /home/tong/.ssh/config line 1: Applying options for *
    debug1: Reading configuration data /etc/ssh/ssh_config

    1. 使用的私钥加密算法已经被openssh弃用,如 之前的 ssh-dss 就已经被新版openssh启用了,如果启用,可以如下配置:

    /home/tong [tong@T7] [10:14]
    > cat ~/.ssh/config 
    HOST *
            HostKeyAlgorithms +ssh-dss
            ForwardX11 yes

      还可以通过命令和man手册,查看都支持那些算法。详细操作略。

    2.  万恶的selinux搞得鬼, 禁掉禁掉,stopstop。

      具体操作略。

      然鹅,使用selinux一定有其好处以及必要性,所以还是需要花些时间,学习一下。

      无意中看到的一个参考:

        The SELinux contexts need to be right as well if you didn't disable that. The command "restorecon -R .ssh" should fix that.

    3.  authorized_keys 文件的权限不对,改成644, 记不太清了,记忆的深处好像是有这么回事的。。。

    4.  同样的key,root用户好用,tong用户便不好用。debug之后,发现server返回的是:

    debug3: receive packet: type 51

      google之

      https://superuser.com/questions/1137438/ssh-key-authentication-fails

      当前的权限是:

    [root@T54 ~]# ll -a  /home/tong/  |grep '.ssh'
    drwxrwxr-x. 2 tong tong   29 May 26 09:58 .ssh
    [root@T54 ~]# ll -a  /root/  |grep '.ssh'
    drwxr-xr-x   2 root root   29 May 26 10:04 .ssh
    [root@T54 ~]# 

      改过权限之后,好用了:

    [tong@T54 ~]$ ll -a |grep '.ssh'
    drwxr-xr-x. 2 tong tong   29 May 26 09:58 .ssh
    [tong@T54 ~]$ ll .ssh/
    total 4
    -rw-r--r-- 1 tong tong 389 May 26 09:58 authorized_keys
    [tong@T54 ~]$ 

    -------------------------------  update @ 2017-10-24 ----------------------------

    排除以上情況依然会有key不好使的时候. 这次有被我遇到.

    以往, 一直在ssh的时候使用-vvvv 来排除故障, 然而这种方法其实是愚蠢的. 因为, 这会给黑客们可称之机.

    查看server的 /var/log/secure 日志文件, 将发现更多的错误信息, 如下:

    > sudo tail -f /var/log/secure
    Sep 14 01:26:31 new-server sshd[22107]: Authentication refused: bad ownership or modes for directory /home/dave/.ssh

    我这次遇到错误是:

     Authentication refused: bad ownership or modes for directory /root

    因为root目录的owner被改成了game组.....

  • 相关阅读:
    Spring Boot 自定义属性 以及 乱码问题
    IDEA 修改文件编码
    Gojs简单例子
    无法转换json问题 Error: Model.nodeDataArray value is not an instance of Array or NodeList or HTMLCollection
    java json转换
    git设置HTTP代理
    thymeleaf中的日期格式化
    thymeleaf:字符串Strings常见的使用方法
    thymeleaf+bootstrap,onclick传参实现模态框中遇到的错误
    Thymeleaf教程 (十二) 标签内,js中使用表达式
  • 原文地址:https://www.cnblogs.com/hugetong/p/6907744.html
Copyright © 2011-2022 走看看