大网数据广告活动
服务器运维问答

sftp, chroot + chdir to user home?

· 52CE 我爱测

Have a config that looks like this AllowUsers sftpu Match Group sftpg ChrootDirectory /home/sftp ForceCommand internal-sftp AllowTCPForwarding no X11Forwarding no the passwd entry (group 7700 is named sftpg ) sftpu:x:7700:7700::/…

问题原文

原帖链接 · Déjà vu · CC BY-SA 4.0

Have a config that looks like this

AllowUsers sftpu
Match Group sftpg
    ChrootDirectory /home/sftp
    ForceCommand internal-sftp
    AllowTCPForwarding no
    X11Forwarding no

the passwd entry (group 7700 is named sftpg)

sftpu:x:7700:7700::/home/sftp/allu:/bin/false

and the allu dir

drwxrwxr-x  4 guacam sftpg  4096 Sep 16  2019 /home/sftp/allu/

That almost works. The chroot works, but unlike what the man says

After the chroot, sshd(8) changes the working directory to the user's home directory

the working dir of the user after login is /home/sftp, not /home/sftp/allu, and my guess is that because /home/sftp/allu belongs to guacam and not sftpu (while the sftpg group has rwx access in allu and could write. That's because several users should share that same allu dir).

Unless the config above is flawed, is there a command in the sshd subsystem to either

  • force the chdir (after chroot) to go to the user's home
  • relax a bit the access rules
  • ...

while keeping the same directory tree and accesses?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

sshd can't change the working directory to the user's home directory because it doesn't exist. It therefore leaves the working directory set to /.

You assigned this user the home directory /home/sftp/allu. But then you chroot the user to /home/sftp. That means that relative to the chroot, that directory is at /allu! Not /home/sftp/allu.

You need to know that chroot causes the root directory that the logged in user can access will be changed to some lower point in the filesystem, and that all paths are relative to that. So if a user must access /home/sftp/allu inside a chroot directory /home/sftp, then outside in the real filesystem, the directory would be /home/sftp/home/sftp/allu.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-09-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。