SFTP access akin to jailed shell
OpenSSH (which also provides sftp and scp functionality) has gained chroot functionality in its later versions. Basically you just need to add lines similar to these one to your /etc/ssh/sshd_config
file.
Subsystem sftp internal-sftp
Match group sftpusers
ChrootDirectory /var/www/xy/backup/files/
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
Then create a new group called sftpusers with command groupadd sftpusers
.
The last step is then to create a user belonging to group sftpusers:
useradd -g sftpusers -d /var/www/xy/backup/files yourusername
passwd yourusername
Then just restart your ssh service: /etc/init.d/sshd restart
and you should be all set.
You can use sshd configuration to achieve this. Create a user e.g. fred
then add the following to your sshd_config file
Match user fred
ChrootDirectory /var/www/xy/backup/files
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
This will lock the user fred
to the desired directory and it's sub directories.
The user fred
only needs r--
access to the file and r-x
to the directories. Check the current permissions it may already be able to do this.