I am in the process of setting chroot for sftp and have used a combination of tutorials (source1, source2) and have ended up with the following configuration in /etc/ssh/sshd_config
:
Match Group sftpusers
ForceCommand internal-sftp
ChrootDirectory /var/sftp/
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
The sftp base folder is /var/sftp
and the user was created as follows:
groupadd sftpusers
adduser myuser01
mkdir -p /var/sftp/myuser01
usermod -a -G sftpusers myuser01
chown myuser01:myuser01 /var/sftp/myuser01
systemctl restart sshd
Now when I try a login I end up in the /var/sftp
folder, which demonstrates login works.
Since I want users to end up in the /var/sftp/<userid>
folder, I try setting the following config is sshd_config
, under the Match Group
line :
ChrootDirectory /var/sftp/%u
When I do that I get an error client_loop: send disconnect: Broken pipe
on a login attempt. According to the man page for ssh_config
the variable should be accepted, per:
ChrootDirectory accepts the tokens %%, %h, and %u.
Any ideas?
Env:
- OS: Ubuntu 18.04.4 LTS
- sshd: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017