允许外部承包商仅访问apache webfolder。选项:SFTP Jailing

时间:2016-01-10 10:15:07

标签: apache ftp centos sftp

以下问题:我们运行CentOS网络服务器,并希望为外部承包商授予访问权限,只需访问我们的网络文件夹' / var / www'修改/上传文件。

我尝试过设置SFTP监控(根据以下文档:http://www.thegeekstuff.com/2012/03/chroot-sftp-setup/),但由于以下原因我无法使其工作:整个web文件夹已分配Apache User apache :像往常一样在CentOS中使用apache。但是SFTP需要root:root所有权否则会出现错误:

  

致命:chroot目录组件的错误所有权或模式" / var / www /" [postauth]

那么如何设置SFTP或其他解决方案以保持" www"文件夹apache:apache拥有并允许其他用户访问它?

还有其他方法可以解决这个问题,那么SFTP或SFTP是正确的做法吗?

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

Well, you'd need to make sure that you've set the proper permissions and ownership for the SFTP directory. Also, make sure the jailed user home directory is owned by root:root and chmod it to 755 (so 'Other' user can execute it)..

chown root:root /home/$SFTPUSER
chmod 755 /home/$SFTPUSER

Also, you'd need to make sure that the original web directory is owned by $SFTP user and apache, along with permission 2775.

答案 1 :(得分:1)

我最终是怎么做到的:

创建群组和用户

groupadd webmasters
useradd -g webmasters -d /var/www/ -s /sbin/nologin externalProvider
passwd externalProvider

在sshd_config中设置sftp-server子系统

vim /etc/ssh/sshd_config

退出现有的子系统并添加:

Subsystem       sftp    internal-sftp

添加添加sshd_config的结尾

Match Group webmasters
ChrootDirectory /var/www/
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

重新启动sshd服务

systemctl restart sshd

文件夹权限

文件权限非常关键!如果以下情况适用于您的情况,请仔细检查。

chown -R root:webmasters /var/www/html/
sudo find /var/www/html/ -type f -exec chmod 664 {} \;
sudo find /var/www/html/ -type d -exec chmod 775 {} \;
sudo find /var/www/html/ -type d -exec chmod g+s {} \; # Set SGID in order to keep group for newly created files
sudo chown -R apache:webmasters /var/www/html/ffhs/data/ # As data directory must be writable by apache
chown root:root /var/www/