How to change vsftpd's default directory to / instead of the user's home directory?

Solution 1:

Just add this line to /etc/vsftpd.conf:

local_root=/

Restart the vsftpd service to apply the changes:

sudo systemctl restart vsftpd

Essentially, you can set it to whatever directory you want. You also can use $USER in the path, it will be replaced with user's login.

So, if you set local_root, for example, to /home/$USER/ftp, then when a user connects to your server, he will be directed to the ftp folder in his home directory.

Solution 2:

You can create a chroot list with vsftpd.conf Check this

All the users belonging to ftp-users group goes into /home/ftp-docs/ftp_stuff by default when they login. They cannot navigate in other directories and are restricted to this particular directory.

You do this:

Create a directory by issuing the following command as root:

mkdir -p /home/ftp-docs/ftp_stuff

Then do this:-

chgrp ftp-users /home/ftp-docs/ftp_stuff chmod 3777 /home/ftp-docs/ftp_stuff

In the /etc/vsftpd/vsftpd.conf write this chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list

Put all you ftp-users group userś name in /etc/vsftpd.chroot_list Then in the /etc/passwd file make the home directory of all the users belonging to ftp-users group to /home/ftp-docs/ftp_stuff. Then do the following:

service vsftpd restart

Then login via any user belonging to ftp-users group you will lend into /home/ftp-docs/ftp_stuff. You cant go to the other higher level directories.

you can create multiple entries in the list for multiple groups. the order in which those groups are in the list file will dictate their highest directory I believe.