How to install and configure an FTP server on Linux
Overview:
FTP (File Transfer Protocol) is a protocol used to transfer files between a server and a client. On Linux systems, we can use vsftpd (Very Secure FTP Daemon) as an FTP server to achieve file transfer. This article will introduce how to install and configure the vsftpd server on Linux and provide relevant code examples.
Step 1: Install vsftpd
To install vsftpd server, we can use the following command:
sudo apt-get update sudo apt-get install vsftpd
Step 2: Configure vsftpd
After the installation is complete, we need to do some things with vsftpd configuration. By default, the configuration file is located at /etc/vsftpd.conf. The file can be opened for editing using a text editor (such as vi or nano):
sudo nano /etc/vsftpd.conf
The following are some important configuration options and their descriptions:
For example, if we want to allow local users to access the FTP server and restrict their home directory to the login directory, we can configure it as follows:
anonymous_enable=YES local_enable=YES write_enable=YES chroot_local_user=YES listen=YES
After completing the configuration, save and close document.
Step 3: Restart the vsftpd server
We need to restart the vsftpd server for the configuration to take effect:
sudo systemctl restart vsftpd
Step 4: Set up the firewall rules
If your Linux system has a firewall enabled , you need to configure the firewall to allow FTP traffic through. The following example shows how to configure a firewall rule using ufw (Uncomplicated Firewall):
sudo ufw allow 20/tcp sudo ufw allow 21/tcp sudo ufw enable
This will allow incoming connections on TCP ports 20 and 21, and enable the ufw firewall.
Step 5: Test the FTP server
Now, your FTP server has been installed and configured. You can test by connecting to the server using an FTP client such as FileZilla.
Example steps to use FileZilla to connect to an FTP server:
Code example:
Write a simple shell script to create an FTP user and set its password:
#!/bin/bash echo "请输入用户名:" read username echo "请输入密码:" read -s password sudo useradd $username -m -s /bin/bash sudo echo -e "$password $password" | sudo passwd $username sudo chown $username:$username /home/$username sudo chmod 755 /home/$username sudo systemctl restart vsftpd
Please note that before running the script, make sure you are on the Linux system have sudo permissions.
Conclusion:
Installing and configuring an FTP server are common tasks in Linux system administration. By using the vsftpd server, file transfer can be easily achieved. In this article, we detail how to install and configure vsftpd server on Linux and provide relevant code examples. Hope this article helps you!
The above is the detailed content of How to install and configure an FTP server on Linux. For more information, please follow other related articles on the PHP Chinese website!