Centos下“ssh免密碼登錄不生效”問題

摘要

一般爲了方便運維管理都會配置ssh免密登錄,ssh免密登錄實現也很方便。今天遇到一個完成了配置了卻不能生效的問題。

思考

遇到這個問題一般有以下幾點:

  • authorized_keys文件是否啓用
  • .ssh 和 authorized_keys 文件權限問題

排查

檢查AuthorizedKeysFile配置是否啓用authorized_keys

root@pts/1 $ cat /etc/ssh/sshd_config |egrep AuthorizedKeysFile
AuthorizedKeysFile  .ssh/authorized_keys

沒有問題,繼續檢查.ssh (700) 和 authorized_keys(644) 權限

root@pts/1 $ getfacl /root/.ssh/
getfacl: Removing leading '/' from absolute path names
# file: root/.ssh/
# owner: root
# group: root
user::rwx
group::---
other::---

root@pts/1 $ getfacl /root/.ssh/authorized_keys
getfacl: Removing leading '/' from absolute path names
# file: root/.ssh/authorized_keys
# owner: root
# group: root
user::rw-
group::---
other::---

authorized_keys 權限不對,修改一下chmod 644 authorized_keys

再次嘗試結果發現還是不行。但是該設置的權限都設置了。既然.ssh目錄和其下文件的權限都OK了,那就檢查下其父目錄的權限,也就是這裏的/root的權限

root@pts/1 $ getfacl /root/
getfacl: Removing leading '/' from absolute path names
# file: root/
# owner: ftpuser
# group: ftpuser
user::r-x
group::r-x
other::---

發現這裏/root 的屬主都發生了變化。爲了不影響別的業務情況,保留這裏的ftpuser權限,利用setfacl添加特殊ACL權限

root@pts/1 $ chown -R root:root  /root/
root@pts/1 $ setfacl -m u:ftpuser:rwx /root/

root@pts/1 $ getfacl /root/
getfacl: Removing leading '/' from absolute path names
# file: root/
# owner: root
# group: root
user::rwx
user:ftpuser:rwx        #effective:r-x
group::r-x
mask::r-x
other::r-x

附加

  • 權限問題

    • /root 775
    • /root/.ssh 700
    • /root/.ssh/authorized_keys 644
  • 開啓文件AuthorizedKeysFile .ssh/authorized_keys
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章