Create FTP User for a Specific Directory in Ubuntu

I will set up an FTP server in my Ubuntu. At the end of the process, I will get an IP address, by which I will access the server. To know more about FTP, follow this article.

Here’s an step-by-step guide to setup an FTP server:

  1. First, press CTRL+ALT+T to launch an Ubuntu Terminal.
  2. Now write the command below to update the system:
    sudo apt-get update
    Bash
    Copy
    EXPLANATION
    • apt-get update: Updates the local repository.
  3. Give your password (if necessary) and press ENTER.




    Wait until the updating process is finished.
  4. Copy the following command to install vsftpd package:
    sudo apt-get install vsftpd
    Bash
    Copy
    EXPLANATION
    • apt-get install: Install the given package.
    • vsftpd: A popular open-source FTP server package.
    Here I have installed the vsftpd package to set up the FTP server as it is fast, secure and it can handle a large number of connections efficiently. However, you can use other packages as well.
  5. Then write the following command to open vsftpd.conf file:
    sudo nano /etc/vsftpd.conf
    Bash
    Copy
    EXPLANATION
    • nano: Opens a file in the Nano text editor.
    • /etc/vsftpd.conf: Configuration file for “vsftpd”.

  6. Now edit the vsftpd.conf file like the below:
    write_enable=YES 
    pasv_min_port=40000 
    pasv_max_port=60000
    Bash
    Copy

    Note: You can write the lines or remove the hash (#) from the beginning if the lines already exist. Make sure there are no duplications.

    EXPLANATION
    • write_enable: Determines whether users are allowed to upload files or not.
    • pasv_min_port: Specifies the minimum port for passive mode.
    • pasv_max_port: Specifies the maximum port for passive mode.


  7. Press CTRL+O and ENTER to save; CTRL+X to exist.
  8. Execute the following lines one by one to add rules to the Firewall:
    sudo ufw allow 20/tcp
    Bash
    Copy
    sudo ufw allow 21/tcp
    Bash
    Copy
    sudo ufw allow from any to any port 40000:60000 proto tcp
    Bash
    Copy
    EXPLANATION
    • ufw: Firewall of Ubuntu.
    • allow: Allows incoming traffic on a given port.
    • 20/tcp: Port 20 with TCP protocol which is used to transfer files in active mode.
    • 21/tcp: Port 21 with TCP protocol which allows the server and client to communicate.
    • from any to any port 40000:60000 proto tcp: Allows traffic from port 40000 to port 60000.


  9. Use the following two commands to restart the FTP server and see its status:
    sudo systemctl restart vsftpd
    Bash
    Copy
    sudo systemctl status vsftpd
    Bash
    Copy
    EXPLANATION
    • systemctl: Is used to control system services.
    • restart: Restart a system service.
    • status: Shows the current status of service.
    • vsftpd: Name of the FTP service.



    Your server is up and running if you see “active (running)” as in the image above. Well done!
  10. Finally, insert the command below and hit ENTER to find the IP address of your FTP server:
    ifconfig
    Bash
    Copy
    EXPLANATION
    • ifconfig: Displays network interface parameters including IP address.
    Note: If your system doesn’t have “ifconfig”, use the following command to install it
    sudo apt-get install net-tools
    Bash
    Copy
    The IP address of my server is 192.168.235.129.


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.