Install FTP in Ubuntu/Linux

OS: Ubuntu  20.04 64bit

1. Download and install vsftpd

Under Ubuntu, just one command is enough:

sudo apt-get install vsftpd

2. Edit configuration items 

In the previous step, if the download and installation is complete, we can go to the /etc directory and check whether the following file appears:

vsftpd.conf

 If there is one, open it for editing:

sudo vim vsftpd.conf

This configuration file has a lot of content by default, and there are a lot of comments, which may not be displayed on one screen:

It is good to leave some items as they are, and some items are commented out by default and need to be turned on. Simple arrangement is as follows:

listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
diemessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log #建议修改日志文件保存的位置
xferlog_std_format=YES
ftpd_banner=Welcome to FTP service.
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
utf8_filesystem=YES

The content of the file is very large, especially in the command line environment, it looks very eye-catching, so you should check it carefully.

Most of the configuration items may be enabled by default. The only suggestion is to change the directory of the log file to other locations when conditions permit, such as additionally mounted data hard disks, etc. Remember to release the log file Save read and write permissions for the directory.

3. Create ftp user

Add a new user to the system with the following command:

sudo useradd ftpuser

Create a password for the new user:

sudo passwd ftpuser

Create a dedicated directory under /home for ftp users:

sudo mkdir /home/ftpuser

Change the ownership of this exclusive directory:

sudo chown ftpuser:ftpuser /home/ftpuser

Generally speaking, the directory of Ubuntu under the /home path is the default directory of the user. It is best not to delete this directory, so modify the permissions of this directory:

sudo chmod 555  /home/ftpuser

Continue to create another directory under this directory, which can be added with write permission:

sudo mkdir /home/ftpuser/share
sudo chmod 777 /home/ftpuser/share

The user accounts added so far are actually the user accounts of the operating system, and we have to add this user account for the ftp itself.

Back in the /etc directory, remember the following entry in the configuration file from the previous step:

chroot_list_file=/etc/vsftpd.chroot_list

Where is the file specified by this item, we will go to this location to create this file (it can also be reversed, first create the file, and then go back to modify the configuration file):

sudo vim /etc/vsftpd.chroot_list

In this file, add the newly created ftp user:

Just write the account name. If there are other accounts that can log in to ftp, write one per line.

 Fourth, start the service

You can check the status of the service with the following command:

service vsftpd status

"Active: active(running)"  in the figure above indicates that the service is running.

Use the following command to restart the service to make the configuration we modified before take effect:

service vsftpd restart

5. Test connection

Before testing, please make sure port 21 on the server is open (the default port for ftp is 21).

I used the FileZilla client for testing. When using FileZilla, you need to set the connection mode to "active":

It is enough to be able to connect and display the directory we configured on the server before. You can try to upload a file. 

Guess you like

Origin blog.csdn.net/freezingxu/article/details/125529691