Home > Operation and Maintenance > Linux Operation and Maintenance > How to install and configure an FTP server on Linux

How to install and configure an FTP server on Linux

PHPz
Release: 2023-07-05 10:19:39
Original
4367 people have browsed it

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
Copy after login

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
Copy after login

The following are some important configuration options and their descriptions:

  • anonymous_enable: Set to YES. Allow anonymous users to access the FTP server.
  • local_enable: Set to YES to allow local users to access the FTP server.
  • write_enable: Set to YES to allow users to upload files to the FTP server.
  • chroot_local_user: Set to YES to limit the user's home directory to the login directory.
  • anonymous_root: Specify the root directory of anonymous users.
  • listen: Specify the IP address that the FTP server listens to.

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
Copy after login

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
Copy after login

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
Copy after login

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:

  1. Open FileZilla and click "File" - "Site Manager".
  2. In Site Manager, click "New Site" and enter the relevant information (such as hostname, port, username, and password).
  3. Click the "Connect" button and FileZilla will try to connect to the FTP server.
  4. If the connection is successful, you will be able to see the files and directories on the 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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template