I created a new user called phone for the client, and created a new directory /home/phone as his home directory. Next create some files for testing purpose.
1 2 |
cd /home/phone touch a b c |
Then modify /etc/ssh/sshd_config to set chroot configuration
1 2 3 |
Match User phone ForceCommand internal-sftp ChrootDirectory /home/phone |
But logging in with this new user and run ls
command, no files are listed, it returns nothing.. But if I run ls in ssh, the files are shown.
1 2 |
root@iZbp14uomoa9zt7kqaxumcZ:/home/phone# ls a b c |
After trying lots of time, the reason is found: It's because there is no "x" permission for /home/phone directory..
1 2 |
root@iZbp14uomoa9zt7kqaxumcZ:~# ls -lh /home drw-r--r-- 3 root root 4.0K Sep 3 11:34 phone |
What is "x" permission?
The "x" permission for directory is used to traverse directory. And the "x" permission for file is for file execution.
Then run following command to add "x" permission for /home/phone
1 |
chmod 744 /home/phone |
And try running ls
command in sftp again, the issue is fixed now, we can see files are listed now.