How to change default ftp directory?
Solution 1
The ftp directory defaults to the user's HOME
directory, so the easiest way to achieve your goal is to create a new user and set his HOME
directory to /var/www/myApplication
:
usermod -d /var/www/myApplication/ exampleuser
If you want to restrict the access to this directory you need to set
chroot_local_user=YES
in your vsftpd.conf
. Then restart the vsftpd service with:
service vsftpd restart
There may be an even simpler way, see here:
To change the default login directory for vsftpd, change the ftp user home directory in
/etc/passwd
:ftp:x:116:116:vsftpd daemon:/var/vsftpd:/bin/false
The ftp user (userID=116) home directory changed to
/var/vsftpd
. This will allow the default/anonymous/unknown user to land into a specific place(/var/vsftpd).
Solution 2
I am not really sure how you went about setting this up, but you need to install vsftpd
.
Steps:
-
Install
vsftpd
:sudo apt-get install vsftpd
-
Make backup of
vsftpd.conf
:sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
-
Setup firewall rules:
sudo ufw allow 20/tcp sudo ufw allow 21/tcp sudo ufw allow 990/tcp sudo ufw allow 40000:50000/tcp sudo ufw status
-
Don't have firewall, then install:
sudo apt-get install ufw
- Enable:
sudo ufw enabe
-
-
Create a user and make the home directory this
/var/www/ftp/myApplication
- create an additional folder called
ftp
as seen above in case you need to add more folders for other users. -
Create user:
sudo usermod -d /var/www/ftp/myApplication ftpuser
- create an additional folder called
-
Set its ownership, and be sure to remove write permissions with the following commands
sudo chown nobody:nogroup /var/www/ftp sudo chmod a-w /var/www/ftp
-
Assign ownership to the
myApplication
foler to userftpuser
sudo chown ftpuser:ftpuser /var/www/ftp/myApplication
-
Setup
/etc/vsftpd.conf
add the following configurations:# Allow anonymous FTP? (Disabled by default). anonymous_enable=NO # # Uncomment this to allow local users to log in. local_enable=YES write_enable=YES # Prevent the FTP-connected user from accessing any files or commands outside # the directory tree chroot_local_user=YES # Add a user_sub_token in order to insert the username in our local_root directory # path so our configuration will work for this user and any future users that might # be added user_sub_token=$USER local_root=/var/www/ftp # Set up the configuration so that access is given to a user only when they # are explicitly added to a list rather than by default userlist_enable=YES userlist_file=/etc/vsftpd.userlist userlist_deny=NO
-
Create and add user to the user_list:
echo "ftpuser" | sudo tee -a /etc/vsftpd.userlist
-
Restart
daemon
to load new configurations:sudo systemctl restart vsftpd
Source(s):
Related videos on Youtube
Mr world wide
Updated on September 18, 2022Comments
-
Mr world wide over 1 year
When I connect with FTP using a pem file it is connecting fine and by default, it is showing this directory:
/home/ubuntu
Now I am trying to change the
/home/ubuntu
directory to/var/www/myApplication
. I am new to Linux can anyone tell which commands I need to use?And how can I see the default ftp path there is no
vsftpd
folder/files in my/etc
folder?