Linux shell将sftp用户限制在他们的主目录中?

MrF*_*dge 34 linux shell sftp

我需要让SFTP访问我服务器上的webroot中的目录.我已将ben_files设置为用户并将其主目录设置为

/var/www/vhosts/mydomain.com/files

如果他连接普通的旧FTP,那就没关系了 - 他仅限于那个目录,但要启用SFTP,我必须将他添加到bin/bash shell,这会突然打开我的整个服务器......

有没有办法给他SFTP访问但没有打开我的所有目录?我真的很喜欢他仅限于他的家;)

谢谢!

eph*_*ent 46

OpenSSH≥4.8支持ChrootDirectory指令.

添加到/etc/sshd_config或者/etc/ssh/sshd_config您的设置的全局sshd配置文件是:

Match user ben_files
        # The following two directives force ben_files to become chrooted
        # and only have sftp available.  No other chroot setup is required.
        ChrootDirectory /var/www/vhosts/mydomain.com/files
        ForceCommand internal-sftp
        # For additional paranoia, disallow all types of port forwardings.
        AllowTcpForwarding no
        GatewayPorts no
        X11Forwarding no

  • @ephemient是的,他们被拒绝使用sftp.但是,我意识到我的问题是主目录的所有权.我把它设置为root:root 755,这一切都很好 (3认同)