FTP
From the Ubuntu documentation:
Securing FTP
There are options in /etc/vsftpd.conf
to help make vsftpd more secure. For example users can be limited to their home directories by uncommenting:
chroot_local_user=YES
You can also limit a specific list of users to just their home directories:
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
After uncommenting the above options, create a /etc/vsftpd.chroot_list
containing a list of users one per line. Then restart vsftpd:
sudo /etc/init.d/vsftpd restart
SFTP
Edit /etc/ssh/sshd_config
:
Set subsystem sftp internal-sftp
if necessary.
Add the following:
Match user theUserName
ChrootDirectory %h
ForceCommand internal-sftp
Save and test the configuration by running sshd -t
. If this is successful, restart ssh
afterwards to apply changes.
Depending on your exact setup, the folder you specify as ChrootDirectory
(%h
is the user's home) must be owned by root
with no write permissions for others. So it's not exactly a real home directory.