목. 8월 7th, 2025

Introduction

File Transfer Protocol (FTP) remains a reliable method for sharing files across networks. In this guide, you’ll learn how to configure a secure FTP server on Linux using vsftpd (Very Secure FTP Daemon), the most trusted FTP server for Unix-like systems. Whether you’re sharing project files or managing a website, these steps will get you up and running in minutes.


Step 1: Install vsftpd

Open your terminal and install vsftpd using your distribution’s package manager:

  • Debian/Ubuntu:
    sudo apt update && sudo apt install vsftpd  
  • RHEL/CentOS:
    sudo dnf install vsftpd  # or sudo yum install vsftpd  

Start and enable the service:

sudo systemctl start vsftpd  
sudo systemctl enable vsftpd  

Step 2: Configure vsftpd

Edit the configuration file with your preferred text editor (e.g., nano):

sudo nano /etc/vsftpd.conf  

Key Settings to Update:

  1. Allow local user logins (uncomment or add):
    local_enable=YES  
  2. Permit file writing:
    write_enable=YES  
  3. Restrict users to their home directories (prevent access to other system areas):
    chroot_local_user=YES  
  4. (Optional) Allow passive mode for firewall/NAT compatibility:
    pasv_enable=YES  
    pasv_min_port=40000  
    pasv_max_port=50000  
  5. Block anonymous access (recommended for security):
    anonymous_enable=NO  

Save changes and restart vsftpd:

sudo systemctl restart vsftpd  

Step 3: Configure Firewall Rules

Allow FTP traffic through your firewall:

  • UFW (Ubuntu):
    sudo ufw allow 20/tcp  
    sudo ufw allow 21/tcp  
    sudo ufw allow 40000:50000/tcp  # Passive mode port range  
    sudo ufw reload  
  • firewalld (RHEL/CentOS):
    sudo firewall-cmd --permanent --add-service=ftp  
    sudo firewall-cmd --permanent --add-port=40000-50000/tcp  
    sudo firewall-cmd --reload  

Step 4: Create an FTP User

Option A: Use an Existing System User

Ensure the user has a valid home directory (e.g., /home/username).

Option B: Create a Dedicated FTP User

  1. Create a user (e.g., ftpuser) without shell access:
    sudo useradd -m -d /home/ftpuser -s /bin/bash ftpuser  
  2. Set a password:
    sudo passwd ftpuser  
  3. Grant ownership of the FTP directory:
    sudo chown -R ftpuser:ftpuser /home/ftpuser  

Step 5: Test Your FTP Server

  1. From Your Local Network:
    Use an FTP client like FileZilla or the ftp command-line tool:

    ftp your_server_ip  

    Log in with your username and password.

  2. External Connection Test:
    Use a public IP or domain name. Ensure port forwarding is enabled on your router if behind NAT.


Security Best Practices

  1. Use FTPS (FTP over SSL/TLS):

    • Generate an SSL certificate:
      sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \  
      -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem  
    • Add to /etc/vsftpd.conf:
      rsa_cert_file=/etc/ssl/private/vsftpd.pem  
      rsa_private_key_file=/etc/ssl/private/vsftpd.pem  
      ssl_enable=YES  
  2. Limit User Access:
    Restrict specific users via:

    userlist_enable=YES  
    userlist_file=/etc/vsftpd.userlist  # Add usernames, one per line  
    userlist_deny=NO  # Only listed users can access  
  3. Regular Updates:
    Keep vsftpd updated:

    sudo apt upgrade vsftpd  # Debian/Ubuntu  
    sudo dnf update vsftpd   # RHEL/CentOS  

Troubleshooting Tips

  • Connection Timeouts:
    Check firewall/NAT settings and passive mode ports.
  • Permission Errors:
    Verify directory ownership (chown) and vsftpd.conf write permissions.
  • Logs:
    Inspect logs at /var/log/vsftpd.log.

Conclusion

You’ve now set up a secure FTP server on Linux! For small teams or personal use, this provides a straightforward way to share files. For public-facing servers, always enforce FTPS and strong passwords. Explore advanced options like virtual users or rate limiting in the official vsftpd documentation.

> Next Steps:
> – Configure automated backups via FTP scripts.
> – Integrate with SSH/SFTP for enhanced security.

Have questions? Share them in the comments below! 🐧🔒

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다