I'm trying to set up a custom root directory (/sftp/root
) for an SFTP user.
I have tried the two solutions I found around, but neither seems to work.
With the "default" /etc/ssh/sshd_config
Match User sftpuser
PasswordAuthentication yes
X11Forwarding no
AllowTcpForwarding no
PermitTunnel no
AllowAgentForwarding no
ForceCommand internal-sftp
I logged (as expected) into the home directory.
sftp> pwd
Remote working directory: /home/sftpuser
First, I tried to define the -d
option.
Match User sftpuser
PasswordAuthentication yes
X11Forwarding no
AllowTcpForwarding no
PermitTunnel no
AllowAgentForwarding no
ForceCommand internal-sftp -d /sftp/root
But the outcome was the same.
sftp> pwd
Remote working directory: /home/sftpuser
Then, I tried the ChrootDirectory
Match User sftpuser
PasswordAuthentication yes
ChrootDirectory /sftp/root
X11Forwarding no
AllowTcpForwarding no
PermitTunnel no
AllowAgentForwarding no
ForceCommand internal-sftp
With the following permissions
ubuntuuser@inlab123:/$ ls -l
drwxr-xr-x 3 root root 4096 Jun 26 08:47 sftp
ubuntuuser@inlab123:/$ ls -l /sftp
total 4
drw-rw-rw- 2 sftpuser sftpuser 4096 Jun 26 09:16 root
But I got
Connection to 101.0.6.769 closed by remote host.
Connection closed
Finally, I tried
Match User sftpuser
PasswordAuthentication yes
ChrootDirectory /sftp
X11Forwarding no
AllowTcpForwarding no
PermitTunnel no
AllowAgentForwarding no
ForceCommand internal-sftp -d /root
with the following outcome.
sftp> pwd
Remote working directory: /
What am I missing here?