How to Create FTP User for Specific Directory in Ubuntu [4 Steps]

Let’s say you are an administrator and you want to keep your FTP server organized, secured, and manage the resource efficiently. One way to do it is by specifying different directories for different users. In this article, I will show you how to create an FTP user for a specific directory in Ubuntu in simple steps. Remember, you can follow the same process for multiple users.

Requirements to create FTP user for specific directory:

  • A server computer (Ubuntu installed in VMWare).
  • A client computer (Ubuntu installed in Windows Subsystem for Linux).
  • Internet Connection.

Process flow chart to create FTP user for specific directory:Process flow chart for "ubuntu create ftp user for specific directory"

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS

4 Steps to Create FTP User for a Specific Directory in Ubuntu

Now I will show you how to create an FTP user for a specific directory in Ubuntu. An FTP user is a like a regular user with access to an FTP server. Here I will use Ubuntu installed in VMWare as the server and Ubuntu installed in WSL (Windows Subsystem for Linux) as the client. You can install Ubuntu in WSL following this article.

Step 01: Create a User in Ubuntu

In the beginning, I will create a user in my Ubuntu using the adduser command. The command asks for the password and other necessary information. To know more about creating users, follow this article. I will create a user named “ftp_user” here. To do so, follow these steps:

  1. At first, open a Terminal in Ubuntu.
  2. Insert the following command to create a user:
    sudo adduser ftp_user
    EXPLANATION
    • sudo: Grants root privileges.
    • adduser: Create a new user.
    • ftp_user: Name of the user.
  3. Give your password.
  4. Now set a password for the user.
  5. Retype the password and press ENTER.
  6. Give additional information if you like or keep pressing ENTER to skip.
  7. Finally press “Y” to complete the process.create a FTP user for a specific directory in Ubuntu

Step 02: Setup an FTP Server

Secondly, 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
    EXPLANATION
  3. Give your password (if necessary) and press ENTER.Updating UbuntuWait until the updating process is finished.
  4. Copy the following command to install vsftpd package:
    sudo apt-get install vsftpd
    EXPLANATION
    • apt-get install: Install the given package.
    • vsftpd: A popular open-source FTP server package.

    Setting up FTP server for "ubuntu create ftp user for specific directory"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
    EXPLANATION
    • nano: Opens a file in the Nano text editor.
    • /etc/vsftpd.conf: Configuration file for “vsftpd”.
    Opening vsftpd.conf file
  6. Now edit the vsftpd.conf file like the below:
    write_enable=YES
    
    pasv_min_port=40000
    
    pasv_max_port=60000

    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.
    Allowing uploading and specifying ports 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
    sudo ufw allow 21/tcp
    sudo ufw allow from any to any port 40000:60000 proto tcp
    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.
    Adding rules to the firewall
  9. Use the following two commands to restart the FTP server and see its status:
    sudo systemctl restart vsftpd
    sudo systemctl status vsftpd
    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.

    Restarting server and checking its statusYour 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
    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
    Finding IP address of the serverThe IP address of my server is 192.168.235.129.


Step 03: Specify Directory

In this section, I will create a directory. Then configure my FTP server so that only a particular user has access to that directory. In this case, the user is “ftp_user”. Now do the following:

  1. At the beginning, launch a Terminal in Ubuntu.
  2. Write the following command to create a directory and press ENTER:
    sudo mkdir -p /var/ftp/ftp_user
    EXPLANATION
    • sudo: Grants root privileges.
    • mkdir: Creates a directory.
    • -p: Is used to create parent directories and subdirectories.
    • /var/ftp/ftp_user: Specific directory for user “ftp_user”.
    Creating directory for "ubuntu create ftp user for specific directory"
  3. Copy the command below to give ownership to your user:
    sudo chown ftp_user:ftp_user /var/ftp/ftp_user
    EXPLANATION
    • chown: Changes ownership.
    • ftp_user:ftp_user: Setting “ftp_user” as User and Group.
    • /var/ftp/ftp_user: Specific directory for user “ftp_user”.
  4. Now insert the command below to create the “user_config_dirdirectory and hit ENTER:
    sudo mkdir -p /etc/vsftpd/user_config_dir
    EXPLANATION
    • mkdir: Creates a directory.
    • -p: Is used to create parent directories and subdirectories.
    • /etc/vsftpd/user_config_dir: Path of the user configuration directory which contains all the settings for the user.
  5. Execute the following command to create and open a file:
    sudo nano /etc/vsftpd/user_config_dir/ftp_user
    EXPLANATION
    • nano: Opens a file in the Nano text editor.
    • /etc/vsftpd/user_config_dir/ftp_user: “ftp_userfile in the user configuration directory.

    Creating user config directoryHere I have created a “user_config_dir” directory, where I will place all the configuration files of the users. Then I created a file with the same name as the user.
    Note: The filename should be similar to the username.
  6. Now add the following line in the user configuration file:
    local_root=/var/ftp/ftp_user
    EXPLANATION
    • local_root: Sets a local root directory for a user.
    • /var/ftp/ftp_user: Local root directory of the user “ftp_user”.
    Setting home directory for the user
  7.   Insert the command below to open the vsftpd.conf file:
    sudo nano /etc/vsftpd.conf
    EXPLANATION
    • /etc/vsftpd.conf: Path of the vsftpd configuration file.
    Open the configuration file of the server
  8. Add the following line in the vsftpd.conf file:
    user_config_dir=/etc/vsftpd/user_config_dir/
    EXPLANATION
    • user_config_dir: Sets the directory where per-user configuration files are stored.
    • /etc/vsftpd/user_config_dir/: Path where the user’s configuration files are stored.
    Mentioning user config directory for in the vsftpd.conf file for "ubuntu create ftp user for specific directory"
  9. Finally, restart the server by using the following command:
    sudo systemctl restart vsftpd
    EXPLANATION
    • systemctl: Is used to control system services.
    • restart: Restart a system service.
    • vsftpd: Name of the FTP service.
    Restarting the server
    Note: If you want to specify directories for multiple users, follow the same process shown here.

Step 04: Verify the Process

Finally, I will connect to my FTP server from the client computer, which is Ubuntu installed in WSL (Windows Subsystem for Linux) in my case. For your information, I have used the Windows Terminal program to customize the output.  Then I will check if the directory is my specified directory or not. To achieve similar goal, follow the below steps:

  1. Launch Ubuntu on your client computer.
  2. Insert the following command to connect to the FTP server:
    ftp [email protected]
    EXPLANATION
    • ftp: Command to access the FTP server.
    • ftp_user: Name of the user.
    • 192.168.235.129: IP address of the server.
  3. Provide the password associated with the user.
  4. Write the following command to print the current path:
    pwd
    EXPLANATION
    • pwd: Print the current directory.

    Accessing the server from client to verify this "ubuntu create ftp user for specific directory"In the output, you can see the current path is “/var/ftp/ftp_user” which we have defined earlier.


Restrict FTP User From Changing Directory

If you want to prevent an FTP user from changing the directory, you can follow the steps shown here. First, I will remove writing permissions for all from the directory, then edit the vsftpd.conf file. Here’s how:

  1. At the beginning, open a Terminal in Ubuntu.
  2. Copy the following command to remove write permission:
    sudo chmod a-w /var/ftp/ftp_user
    EXPLANATION
    • chmod: Changes permissions.
    • a-w: Removing writing permissions from all.
    • /var/ftp/ftp_user: Specific directory of the “ftp_user”.
  3. Insert the command below to open the vsftpd.conf file:
    sudo nano /etc/vsftpd.conf
    EXPLANATION
    • nano: Opens a file in the Nano text editor.
    • /etc/vsftpd.conf: Path of the vsftpd configuration file.
    Removing writing permission from all
  4. Now edit the vsftpd.conf file like the below:
    chroot_local_user=YES
    EXPLANATION
    • chroot_local_user: If enabled, it jails local users to their own directories.
    Jailing users to their home directory
  5. Now launch a Ubuntu Terminal in the client computer and write the following command to access the FTP server:
    ftp [email protected]
    EXPLANATION
    • ftp: Command to access the FTP server.
    • ftp_user: Name of the user.
    • 192.168.235.129: IP address of the server.
  6. Then try to change your directory like the below:
    cd /etc
    EXPLANATION
    • cd: Changes directory.
    Verifying if users are rally restricted to their home directory or notIt is showing “Failed to change directory”, that means the user is restricted to its home directory.

How to Disable FTP User in Linux

Disabling FTP user means disallowing a user’s access to the FTP server. You should have a “ftpusersfile in your Linux system. You just need to add the name of the user you want to disable there. Just do the following:

  1. Launch a Ubuntu Terminal by pressing CTRL+ALT+T.
  2. Open the “ftpusers” file using the command below:
    sudo nano /etc/ftpusers
    EXPLANATION
    • /etc/ftpusers: File that contains the list of all disabled users.
  3. Provide the password (if necessary).Opening the "ftpusers" file
  4. Now add the user who you want to disable:
    ftp_user

    Adding 'ftp_user" to the disallowed list

  5. Now launch a Ubuntu Terminal on your client computer and execute the following command to access the FTP server:
    ftp [email protected]
    EXPLANATION
    • ftp: Command to access the FTP server.
    • ftp_user: Name of the user.
    • 192.168.235.129: IP address of the server.
  6. Give the password associated with the user.Checking if changing directory is possibleYou should see a “Login failed” message. Thus the user is disabled now.


Conclusion

In this article, I have shown all the steps necessary to create an FTP user for a specific directory in Ubuntu. I have also added some complimentary information and questions. Hopefully, you have found what you have been looking for in this article. Now you will be able to create an FTP user with a specific directory in Ubuntu.

People Also Ask

What is FTP user account?

An FTP user account is a type of account that allows file transferring. It is similar to a standard user account consisting of a username and password.

How do I get FTP permissions?

You will need to reach out to the administrator of an FTP server. He will provide you necessary credentials as a username and password. He will also decide your access to system resources.

What is FTP user name directory?

FTP user name directory refers to a specific directory a user is redirected to when they connect to an FTP server. The directory usually has a similar name as the user. However, the directory can be changed.

What is FTP root directory?

It is the default directory of a user. If a user logs into an FTP server, he goes to that directory. Then he can navigate to other directories starting from there. It can vary according to the configuration of a server but in general, it is the user name directory.

What are the different types of users in FTP?

There are generally two types of FTP users- Anonymous users and Authenticated users. Anonymous users don’t require any username and password and they have access to a limited set of files. On the other hand, authenticated users have the necessary credentials to access an FTP server and they enjoy more privileges.

How many users can connect to FTP server?

The number of users that can connect to an FTP server depends on some factors such as hardware, network infrastructure, firewall and FTP software. However, any FTP server should handle 50 to 500 connections simultaneously without any issues.

How do I access the root folder in FTP?

First, you will need the necessary credentials to log into an FTP server. Then you can use the following command to access the root folder in the FTP server:

cd /

Do I need to open port 20 for FTP?

Yes. You need to open port 20 as FTP uses this to transfer files in active mode. However, if you use passive mode, you don’t need open this port.

Why does FTP use 2 ports?

FTP uses two ports. Port 21 is used to control the connection, commands can be sent and executed through this port. Whereas, port 20 is used to transfer data in active mode. By using two ports, FTP ensures control traffic and data traffic don’t interfere with each other.

How to create ftp user in Ubuntu?

To create a ftp user in Ubuntu, open the terminal and run the command sudo useradd -m ftp_user_name. It will create new ftp user with its home directory. Additionally, run the command sudo passwd ftp_user_name to provide password for the new ftp_user_name account.

How to set up ftp server on Ubuntu?

To set up the ftp server on Ubuntu, run sudo apt update to refresh repositories, then install ftp server package vsftpd using the command sudo apt install vsftpd, open file configuration file with sudo nano /etc/vsftpd.conf and enable ftp access to YES, and restart the server with sudo systemctl restart vsftpd. In addition, you can test the server by connecting it to Ubuntu using its actual hostname or IP address.

Relaed Articles

5/5 - (4 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment