Build an FTP server on Ubuntu to meet file transfer and management needs. The following are the detailed steps to build: 1. Install vsftpd: First you need to install an FTP server package called vsftpd. Enter the following command in the terminal to install: ```bash sudo apt-get update sudo apt-get install vsftpd ``` 2. Configure vsftpd: After the installation is complete, vsftpd needs to be configured. Edit the configuration file/etc/vsftpd.conf, you can use a text editor like nano or vim. In the configuration file, various parameters can be modified as needed, such as allowing anonymous access, setting upload and download restrictions, etc. 3. Restart the vsftpd service: After modifying the configuration, you need to restart the vsftpd service for the changes to take effect. Enter the following command in the terminal: ```bash sudo systemctl restart vsftpd ``` 4. Set firewall rules: If the server has a firewall enabled, the port that allows the FTP service is required. Enter the following command in the terminal: ```bash sudo ufw allow 20/tcp sudo ufw allow 21/tcp ``` 5. Create FTP users: In order to use FTP services, one or more FTP users need to be created. The useradd and passwd commands can be used to create users and set passwords. For example, create a user named ftpuser and set the password to mypassword: ```bash sudo useradd ftpuser sudo passwd ftpuser ``` 6. Authorized FTP user: In order to allow the newly created user to use the FTP service, it needs to be added to the authentication file of vsftpd. Edit the/etc/vsftpd.user _ list file and add the information of the new user: ```bash sudo nano /etc/vsftpd.user_list ``` Add the following to the file (replace ftpuser with the actual username): ``` ftpuser mypassword*=*,NOPASSWD:ALL ``` Save and exit the editor. So far, an efficient and stable FTP server has been built on Ubuntu, which can meet the needs of file transfer and management.
This article will take you to build an efficient and stable FTP server step by step from scratch.
I. Preparation.
First, make sure you have the Ubuntu operating system installed. If not, you can download and install it from the official Ubuntu website.
After the installation is complete, update the system package:
sudo apt update
sudo apt upgrade
II. Install VSFTPD.
VSFTPD (Very Secure FTP Daemon) is a secure and efficient FTP server software. We will use it to build our FTP server.
1. Install VSFTPD:
sudo apt install vsftpd
2. Start and enable the VSFTPD service:
sudo systemctl start vsftpd
sudo systemctl enable vsftpd
III. Configure VSFTPD.
The configuration file for VSFTPD is located at /etc/vsftpd.conf
。We need to make some changes to this file to meet our needs.
1. Open the configuration file:
sudo nano /etc/vsftpd.conf
2. Make the following modifications:
plaintext
# 允许匿名登录
anonymous_enable=NO
# 启用本地用户登录
local_enable=YES
# 允许上传文件
write_enable=YES
# 启用chroot限制,提高安全性
chroot_local_user=YES
# 允许列表中指定哪些用户可以访问FTP
allow_writeable_chroot=YES
Save and close the file.
3. Configure user permissions and directories:
Suppose we have a user ftpuser
, We need to create a directory for this user and set the appropriate permissions.
sudo adduser ftpuser
sudo passwd ftpuser # 设置用户密码
sudo mkdir -p /home/ftpuser/ftp
sudo chown -R ftpuser:ftpuser /home/ftpuser/ftp
sudo chmod -R 755 /home/ftpuser/ftp
4. Modify the VSFTPD configuration file to specify the user home directory:
sudo nano /etc/vsftpd.conf
Add or modify the following lines:
plaintext
local_root=/home/ftpuser/ftp
Save and close the file.
Fourth, the firewall configuration.
In order to allow external access to the FTP server, we need to configure a firewall. Assuming you are using UFW (Uncomplicated Firewall), you can configure it as follows:
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 21000:21000/tcp
sudo ufw reload
V. Test FTP server.
After everything is configured, we can use the FTP client to test whether the server is working properly. You can use command line tools ftp
Or graphical tools such as FileZilla.
Use command line test:
ftp localhost
Enter username ftpuser
And after the password, you should be able to see prompts like the following:
plaintext
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>@your-server-ip:~$ ls
If you can see the directory list, it means that the FTP server has been successfully built and run.
VI. Advanced configuration (optional).
\n#1. SSL/TLS encryption.
To improve security, we can configure VSFTPD to use SSL/TLS encryption. First, install the necessary packages:
sudo apt install vsftpd-ssl
Then, edit the configuration file to enable SSL:
sudo nano /etc/vsftpd.conf
Uncomment the following lines:
plaintext
# RSA certificate to use for SSL encryption (only if it is not in /etc/ssl/private)
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
Save and close the file. Restart the VSFTPD service:
sudo systemctl restart vsftpd
\n#2. Passive mode configuration.
In some network environments, it may be necessary to configure passive mode to increase connection success. Edit configuration file:
sudo nano /etc/vsftpd.conf
Uncomment the following lines and set them to the appropriate value:
plaintext
pasv_enable=YES
pasv_min_port=10000
pasv_max_port=10100
Save and close the file. Restart the VSFTPD service:
sudo systemctl restart vsftpd
VII. Summary.
Through the above steps, we have successfully built an efficient and stable FTP server on Ubuntu. According to actual needs, you can further optimize and configure the server, such as setting user quotas, logging, etc.
Hope this article is helpful and I wish you all the best when using the FTP server!