摘要
一般为了方便运维管理都会配置 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