閱讀389 返回首頁    go 阿裏雲 go 技術社區[雲棲]


綁定秘鑰對功能解析及無法登錄案例一

綁定秘鑰主機上發生什麼

  1. 會修改/ect/ssh/sshd.config增加: PasswordAuthentication no ChallengeResponseAuthentication no 如果原來已經有,也會進行修改。作用是不允許密碼登錄。
  2. 在 root 目錄下創建.ssh 目錄,並在目錄下創建authorized_keys文件。
    BaiduShurufa_2017_6_30_20_47_10

  3. authorized_keys 內容:
    BaiduShurufa_2017_6_30_20_48_15

解除綁定發生什麼

  1. 會修改/ect/ssh/sshd.config 修改成如下: PasswordAuthentication yes ChallengeResponseAuthentication yes 作用是允許密碼登錄。
  2. 清空/root/.ssh/authorized_keys 的內容。 BaiduShurufa_2017_6_30_20_52_13

綁定秘鑰對無法登錄案例一:

  1. 現象就是登錄的時候選擇了正確的秘鑰對,確認後有彈回到登錄界麵。
    BaiduShurufa_2017_6_30_20_54_26

  2. 通過鏈接管理終端進行核查:
    查看/var/log/secure日誌:

    Jun 30 20:53:25 iZ2zec97e3hxz0j4koh7x4Z sshd[13194]: Server listening on 0.0.0.0 port 22.
    Jun 30 20:54:09 iZ2zec97e3hxz0j4koh7x4Z sshd[13205]: Authentication refused: bad ownership or modes for file /root/.ssh/authorized_keys
    Jun 30 20:55:53 iZ2zec97e3hxz0j4koh7x4Z sshd[13206]: Received disconnect from ***.***.***.***: 0: 
    

    ip已使用*** 代替。
    日誌看是 /root/.ssh/authorized_keys 權限不正確,經核實這個文件需要 600 權限。
    使用命令進行修改:

    chmod 600 /root/.ssh/authorized_keys
    

    在測試還是不行,日誌:

    Jun 30 21:04:31 iZ2zec97e3hxz0j4koh7x4Z sshd[13271]: Authentication refused: bad ownership or modes for directory /root/.ssh
    Jun 30 21:04:33 iZ2zec97e3hxz0j4koh7x4Z sshd[13272]: Received disconnect from ***.***.***.***: 0: 
    

    還是一樣權限不對,不過是 /root/.ssh努力權限不對,經核實這兒目錄需要 700 權限

    chmod 700 /root/.ssh/
    

    在測試還是不行,日誌:

    Jun 30 21:09:00 iZ2zec97e3hxz0j4koh7x4Z sshd[13301]: Authentication refused: bad ownership or modes for directory /root
    Jun 30 21:09:02 iZ2zec97e3hxz0j4koh7x4Z sshd[13302]: Received disconnect from  ***.***.***.***: 0
    

    還是一樣權限不對,不過是 /root/努力權限不對,經核實這兒目錄需要 550 權限

    chmod 550 /root/
    

    修改後測試登錄成功。

  3. 問題最終發現是因為運行了chmod -R 777 /root 導致目錄權限不正確,導致使用秘鑰對無法登錄,係統默認目錄的權限不建議修改。

    秘鑰對參考:

    參考:https://help.aliyun.com/document_detail/51792.html?spm=5176.product25365.6.682.aAQiJH

最後更新:2017-06-30 21:51:06

  上一篇:go  協同消費延遲報警
  下一篇:go  MySQL運維之神奇的參數(終結篇)