摘要
一般爲了方便運維管理都會配置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