2021年10月26日 星期二

SFTP Chroot with Public Key Authentication and SELiunx in CentOS

Chroot 後

SSHD 對於 chroot的 userhome/.ssh 的讀寫權限,受到selinux的限制

可以在 /var/log/audit.log裡面看到類似

type=AVC msg=audit(1635139929.544:379): avc:  denied  { read } for  pid=144254 comm="sshd" name="authorized_keys" dev="sda2" ino=50348313 scontext=system_u:system_r:sem_r:sshd_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:var_t:s0 tclass=file permissive=0

 

解法1 :

 把 authorized_key 放到其他資料夾

參考 https://wiki.archlinux.org/title/SFTP_chroot

 

Match Group sftponly
AuthorizedKeysFile /etc/ssh/authorized_keys/%u
ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no PasswordAuthentication no


解法2 :

如果要保持放在 userhome/.ssh

 

安裝 semanage 

yum install policycoreutils-python-utils

 針對  choort 的 userhome/.ssh

執行

semanage fcontext -a -t ssh_home_t /path/to/users/homedirectory/.ssh/
restorecon -v /path/to/users/homedirectory/.ssh/