Ubuntu detailed steps for installing vsftpd FTP

  • 2020-05-17 07:02:20
  • OfStack

vsftpd is an FTP server that complies with the GPL protocol for UNIX systems, including Linux. It's safe and very fast.

This tutorial will show you how to set up your own FTP server on the Linux system.

1. Install vsftpd.

sudo apt-get install vsftpd

2. Replace configuration files.

Open the vsftpd.conf configuration file with a text editor, 1 normally in the /etc directory.

[sudo joe /etc/vsftpd.conf

The following modifications can be made:

The anonymous_enable = YES

to

anonymous_enable=NO

This will prevent users from accessing your FTP server anonymously unless you have a very good reason to do so. And when it comes to network security, I recommend not allowing anonymous access, especially if your FTP server is on Internet.

Of course, with anonymous access disabled, you need to allow the local user to log in, as follows:

The # local_enable = YES

to

local_enable=YES

3. Add an "fake" shell script.

Edit the /etc/shells file and add a non-existent shell name such as /bin/false. This fake shell will restrict access to the system for FTP users.

sudo joe /etc/shells


# /etc/shells: valid login shells 
/bin/sh 
/bin/bash 
/bin/false 

/bin/false is a nonexistent shell that we added. Just like a special device on the red hat Linux system /dev/null 1.

4. Create an FTP user account.

It is important to create a strict FTP user account on shell, which does not exist on the Linux system. In this way, if for any reason someone can successfully escape FTP's chroot environment, he will not be able to perform any user tasks because shell does not exist. First, create a new user.
This must be separated from normal user accounts that have no restricted access because of the way the chroot environment works. Chroot is made from the user's point of view, as if you had kept them at the top level of the file system.

Use the following command to create a user in the /etc/passwd file, which you must do every time you add a new user that allows access to your FTP server.


sudo mkdir -p /home/ftp/ftpuser 
sudo useradd ftpuser -d /home/ftp/ftpuser/ -s /bin/false 
sudo passwd ftpuser 

The -mkdir command will create the ftp/ftpuser directory under /home to handle all FTP users.
-useradd will add a new user named ftpuser to your Linux server.
- finally, the passwd command sets the user's ftpuser password.
Once you have done this, restart the vsftpd service with the following command:

sudo /etc/init.d/vsftpd restart

5. Rewrite the configuration items specified in the user manual on a per-user basis (optional).

If you want to change the behavior of the ftp server on a per-user basis, your application knows that vsftpd has a powerful option that allows you to do so.
If you set user_config_dir to /etc/vsftpd_user_conf and log in as user "chris", vsftpd will apply these Settings in the /etc/vsftpd_user_conf/chris file for the duration of the session, see the user manual for the format of the file!

Note that not all Settings will work for every user; for example, many Settings will only work for previous user sessions that have already been started. These do not affect any behavior Settings for each user, including listen_address, banner_file, max_per_ip, max_clients, xferlog_file, max_clients, xferlog_file, and so on.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: