Detailed explanation of how to build an Ftp server on Ubuntu (success guaranteed)

Detailed explanation of how to build an Ftp server on Ubuntu (success guaranteed)

1. This afternoon, due to the requirements of the course, I had to do an experiment on setting up an FTP server on Ubuntu. However, the experimental instruction manual was still based on technology from N years ago. I searched a lot on the Internet, but everything was vague!

After overcoming numerous difficulties, the experiment was finally successful. I would like to share this experience with everyone in the hope that you can avoid detours!

2. The detailed steps are as follows:

(1) First open the terminal and enter the root mode (enter the command: sudo su in the terminal and press Enter to enter the password);

(2) Install the vsftpd software (first you need to be connected to the Internet, or install it through Synaptic Software! sudo apt-get remove vsftpd )

Command: sudo apt-get install vsftpd 

(3) After successful installation, an ftp file will be created in the srv directory under the file system by default (in the same directory as home). This is the default folder of the ftp server!

(4) Some documents say that the directory automatically created by the FTP server is the FTP folder under the home directory, but I have never found it (usually the home directory is the user's directory). I also cannot find the directory I created myself when accessing FTP!

(5) Add folders and files to the server directory. First, create a folder test under srv/ftp/ (it cannot be created manually, it can only be achieved through commands!)

Command: mkdir /srv/ftp/test

Get the created folder:

Create a few more directories just for testing!

(6) Create a file in the test folder: touch /srv/ftp/test/1.txt file

(7) Edit the 1.txt file: (Due to permission management, you need to use root mode to change the content of the file!)

sudo gedit /srv/ftp/test/1.txt will pop up a notepad file that can only be modified when opened with root permissions |! Add some content

(8) To illustrate a command, reboot!

The command is: sudo /etc/init.d/vsftpd restart

(9) Check whether you have successfully found the IP address of Ubuntu. In the address bar, visit mine: ftp://192.168.136.130/ or ftp://localhost. The following is a screenshot:

Enter test, find the 1.txt file and click to enter!

(10) OK! That's it!

3. The above knowledge introduces the general default configuration. We usually need to configure according to our own needs. The following are some common configurations!

If you need to modify it, you still need to modify it under root privileges using the command: sudo gedit /etc/vsftpd.conf

(1) Anonymous user settings

  • anonymous_enable=YES, change YES to NO to prohibit anonymous users from logging in
  • #anon_mkdir_write_enable=YES , remove the # comment to allow anonymous users to create directories
  • #non_upload_enalbe=YES , remove # to allow anonymous users to upload
  • anon_world_readable_only=YES , allows anonymous users to download, which is prohibited by default, and can be added by yourself.
  • Anon_other_write_enable=YES, if set to YES, in addition to uploading and creating directories, you can also rename and delete files. The default is NO
  • no_anon_password=NO, set it to YES, anonymous users will log in directly without querying the user password.
  • ftp_username=ftp, the default account for anonymous users to log in to the system is ftp, it is best not to change this;
  • chroot_local_user=YES #Restrict local users to their home folders, so that after logging in, they cannot access files outside their home folders. This is for security reasons
  • anon_root=/var/ftp/anon #Specify the root folder after anonymous login, that is, for anonymous users, /var/ftp/anon will be mapped as its root directory

(2) Specifying the FTP service port

  • listen_port=8021, specifies the command channel as 8021, the default is 21
  • listen_data_port=8020, specifies the data channel as 8020, the default is 20

(3) Upload mode settings

  • pasv_enable=YES, whether to allow the use of passive mode, the default is allowed.
  • pasv_min_port=10000, specifies the minimum value of the open port when using passive mode
  • pasv_max_port=10004, specifies the maximum value of the open port when using passive mode.

(4) Vsftp server specifies the IP address

  • listen_address=192.168.0.21, specify FTP, IP address

Note: The use of a specified IP address is allowed only when vsftp is running in standalone mode. If a vsfpd file has been created in the /etc/xinetd.d directory, the disable option in the file must be set to yes.

(5) Lock the user and prohibit the user from leaving the user's home directory

  • chroot_local_user=YES, set it to YES to lock it in the user's home directory, set it to NO to switch

Set the specified user to lock the user home directory:

#chroot_list_enable=YES

#chroot_list_file=/etc/vsftpd.chroot_list

Change it to the following:

chroot_list_enable=NO

chroot_list_file=/etc/vsftpd/vsftpd.chroot_list

Save the above and do the following:

#touch /etc/vsftpdvsftpd.chroot_list

#vi /etc/vsftpd/vsftpd.chroot_list, add the user list to the file, such as: netseek_com

(6) Traffic control of vsftpd server

  • max_clients=100; The maximum number of connections allowed is defined as 100, the default is 0, and the table has no limit
  • max_per_ip=5 ; The number of connections allowed per IP. 0 means no limit. You need to run in standalone mode.
  • anon_max_rate=50000 ; Maximum bandwidth for anonymous users, in bps
  • local_max_rate=200000; Maximum bandwidth for system users

(7) vsftpd customized welcome message

Directory Description Settings

#vi /etc/vsftpd.conf

#dirmessage_enable=YES, remove the # in front.

Then we customize a .message, write what you want to write, and then copy this file to each user's home directory, and that's it.

(9) vsftpd system welcome message settings

ftpd_banner=Welcome to ftp.netseek.com , Yeah!!!

System welcome message file settings

banner_file=/etc/vsftpd/welcome is similar to ftpd_banner, except that banner_file specifies the welcome file.

4. Create a User

But you can't upload files in this way. Because this is an anonymous user, the current directory owner is the root user; if you really want to upload files, create a folder in this directory and name it upload.

$ sudo mkdir /srv/ftp/upload

$ sudo chown ftp:root /srv/ftp/upload

At this time, files can be transferred to the upload directory, but files cannot be uploaded to the root directory. This is an anonymous user. If it is not an anonymous user, this problem does not exist.

1). Modify the configuration file /etc/vsftpd.conf

anonymous_enable=NO

local_enable=YES

write_enable=YES

chroot_local_user=YES 

2). Create a local user

$ sudo useradd ftpuser -m

$ sudo passwd ftpuser

You can then log in to FTP using ftpuser.

6. If an error occurs: 500 OOPS: vsftpd: refusing to run with writable anonymous root

This means that the permissions of the ftp user's home directory are incorrect. The permissions of this directory cannot open all permissions. This is caused by running chmod 777 /srv/ftp. If there is no home directory for the ftp user, of course you have to create one yourself.

The home directory of FTP users cannot be fully open to all users, user groups, or other user groups. The solution is as follows:

# chown root:root /srv/ftp 
# chmod 755 /srv/ftp

7. Open the corresponding ports 21 and 20 on the firewall

8. /etc/init.d/vsftpd restart Restart the service

5. Explanations from Users

The following describes the three types of users supported by vsftpd:

  • 1. Anonymous user, that is, a user who can log in to the FTP server without entering a password. This user name is usually ftp or anonymous; the settings related to anonymous users often start with the anon_ option.
  • 2. Local users, that is, users who can log in to the system on your Linux system. These users are real users on the system. Usually it has its own home, shell, etc. Settings related to local users often start with or contain local_.
  • 3. Virtual user, a user valid only for FTP. These users cannot log in to the Linux system, but can only log in to the ftp server. In fact, a local user is mapped into multiple virtual users that are only valid for the FTP server. Virtual users can have their own FTP configuration files, so they are usually used to set different permissions for different users of the FTP system to achieve security control purposes. Settings related to virtual users begin with guest_.

If you just want to use FTP to share with yourself, you can enable local users;

If you want to share with many people, you can use anonymous users;

If you need to grant different permissions to different user groups, you need to set up more complex virtual users.

mkdir directoryname => create a directory
rmdir empty directory name => delete an empty directory
rm filename filename => delete one or more files
rm –rf non-empty directory name => delete everything under a non-empty directory
touch filename => create an empty file

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Solution for installing opencv 3.2.0 in Ubuntu 18.04
  • Ubuntu16.04/Raspberry Pi Python3+opencv configuration tutorial (sharing)
  • How to configure OpenCV3.2 in Python3.5 on Linux-ubuntu16.04
  • Ubuntu14.04 opencv2.4.8 and opencv3.3.1 multi-version coexistence implementation method
  • How to install opencv3.0.0 in ubuntu14.04
  • Detailed steps to compile and install opencv from source code on Ubuntu 17.04
  • Tutorial on how to install and use Opencv in Ubuntu
  • Python Web project Django deployed on Ubuntu 18.04 Tencent Cloud host
  • Solution to no Chinese input method in Ubuntu
  • How to compile and install opencv under ubuntu

<<:  Implementation of react automatic construction routing

>>:  How to solve mysql error 10061

Recommend

Implementation of ssh non-secret communication in linux

What is ssh Administrators can log in remotely to...

Tutorial on using prepare, execute and deallocate statements in MySQL

Preface MySQL officially refers to prepare, execu...

MySQL million-level data paging query optimization solution

When there are tens of thousands of records in th...

js to achieve simple image drag effect

This article shares the specific code of js to ac...

Native js encapsulation seamless carousel function

Native js encapsulated seamless carousel plug-in,...

How to add fields and comments to a table in sql

1. Add fields: alter table table name ADD field n...

Solve the Docker x509 insecure registry problem

After installing Docker, I encountered the x509 p...

Website redesign is a difficult task for every family

<br />Every family has its own problems, and...

How to install PostgreSQL11 on CentOS7

Install PostgreSQL 11 on CentOS 7 PostgreSQL: The...

Why node.js is not suitable for large projects

Table of contents Preface 1. Application componen...

Pessimistic locking and optimistic locking in MySQL

In relational databases, pessimistic locking and ...

Native JavaScript carousel implementation method

This article shares the implementation method of ...