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.
Key Takeaways
- Creating a User.
- Setting up an FTP server.
- Specifying a Directory for a User.
- Checking the current directory.
- Restricting a user to a directory.
- Disabling an FTP user.
Requirements
- A server computer (Ubuntu installed in VMWare).
- A client computer (Ubuntu installed in Windows Subsystem for Linux).
- Internet Connection.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Watch to Create FTP User for Specific Directory in Ubuntu
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.
Steps to follow >
➊ At first, open a Terminal in Ubuntu.
➋ Insert the following command to create a user:
sudo adduser ftp_user
- sudo: Grants root privileges.
- adduser: Create a new user.
- ftp_user: Name of the user.
❸ Give your password.
❹ Now set a password for the user.
❺ Retype the password and press ENTER.
❻ Give additional information if you like or keep pressing ENTER to skip.
❼ Finally press “Y” to complete the process.
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.
Steps to follow >
➊ First, press CTRL+ALT+T to launch an Ubuntu Terminal.
❷ Now write the command below to update the system:
sudo apt-get update
- sudo: Grants root privileges.
- apt-get update: Updates the local repository.
❸ Give your password (if necessary) and press ENTER.Wait until the updating process is finished.
❹ Copy the following command to install vsftpd package:
sudo apt-get install vsftpd
- sudo: Grants root privileges.
- apt-get install: Install the given package.
- vsftpd: A popular open-source FTP server package.
❺ Then write the following command to open vsftpd.conf file:
sudo nano /etc/vsftpd.conf
- sudo: Grants root privileges.
- nano: Opens a file in the Nano text editor.
- /etc/vsftpd.conf: Configuration file for “vsftpd”.
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.
- 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.
❽ 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
- sudo: Grants root privileges.
- 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.
sudo systemctl restart vsftpd
sudo systemctl status vsftpd
- sudo: Grants root privileges.
- 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.
❿ Finally, insert the command below and hit ENTER to find the IP address of your FTP server:
ifconfig
- ifconfig: Displays network interface parameters including IP address.
sudo apt-get install net-tools
- How to Create a Jenkins User on Ubuntu? [2 Methods]
- How to Create MySQL User in Ubuntu? [2 Cases]
- Create User Without Home Directory in Ubuntu in Just 3 Steps
- How to Create a User in Docker Container Without Docker File?
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:
Steps to follow >
❶ At the beginning, launch a Terminal in Ubuntu.
❷ Write the following command to create a directory and press ENTER:
sudo mkdir -p /var/ftp/ftp_user
- 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”.
sudo chown ftp_user:ftp_user /var/ftp/ftp_user
- sudo: Grants root privileges.
- chown: Changes ownership.
- ftp_user:ftp_user: Setting “ftp_user” as User and Group.
- /var/ftp/ftp_user: Specific directory for user “ftp_user”.
❹ Now insert the command below to create the “user_config_dir” directory and hit ENTER:
sudo mkdir -p /etc/vsftpd/user_config_dir
- sudo: Grants root privileges.
- 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.
❺ Execute the following command to create and open a file:
sudo nano /etc/vsftpd/user_config_dir/ftp_user
- sudo: Grants root privileges.
- nano: Opens a file in the Nano text editor.
- /etc/vsftpd/user_config_dir/ftp_user: “ftp_user” file in the user configuration directory.
local_root=/var/ftp/ftp_user
- local_root: Sets a local root directory for a user.
- /var/ftp/ftp_user: Local root directory of the user “ftp_user”.
sudo nano /etc/vsftpd.conf
- sudo: Grants elevated privileges.
- nano: Opens a file in the Nano text editor.
- /etc/vsftpd.conf: Path of the vsftpd configuration file.
❽ Add the following line in the vsftpd.conf file:
user_config_dir=/etc/vsftpd/user_config_dir/
- 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.
sudo systemctl restart vsftpd
- sudo: Grants root privileges.
- systemctl: Is used to control system services.
- restart: Restart a system service.
- vsftpd: Name of the FTP service.
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.
Steps to follow >
❶ Launch Ubuntu on your client computer.
❷ Insert the following command to connect to the FTP server:
ftp [email protected]
- ftp: Command to access the FTP server.
- ftp_user: Name of the user.
- 192.168.235.129: IP address of the server.
❸ Provide the password associated with the user.
❹ Write the following command to print the current path:
pwd
- pwd: Print the current directory.
- How to Create an FTP User in Ubuntu? [Step-by-Step]
- Create a New SFTP User in Ubuntu with a New SSH Key
- How to Create Group and Add User in Ubuntu? [2 Cases]
- How to Create a Root User in Ubuntu [Step-by-Step]
Complementary Information
In this section, I will add some extra information for your benefit. I hope you will find it helpful.
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.
Steps to follow >
➊ At the beginning, open a Terminal in Ubuntu.
➋ Copy the following command to remove write permission:
sudo chmod a-w /var/ftp/ftp_user
- sudo: Grants root privileges.
- chmod: Changes permissions.
- a-w: Removing writing permissions from all.
- /var/ftp/ftp_user: Specific directory of the “ftp_user”.
❸ Insert the command below to open the vsftpd.conf file:
sudo nano /etc/vsftpd.conf
- sudo: Grants elevated privileges.
- nano: Opens a file in the Nano text editor.
- /etc/vsftpd.conf: Path of the vsftpd configuration file.
chroot_local_user=YES
- chroot_local_user: If enabled, it jails local users to their own directories.
ftp [email protected]
- ftp: Command to access the FTP server.
- ftp_user: Name of the user.
- 192.168.235.129: IP address of the server.
❻ Then try to change your directory like the below:
cd /etc
- cd: Changes 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 “ftpusers” file in your Linux system. You just need to add the name of the user you want to disable there. Just do the following:
Steps to follow >
❶ Launch a Ubuntu Terminal by pressing CTRL+ALT+T.
❷ Open the “ftpusers” file using the command below:
sudo nano /etc/ftpusers
- sudo: Grants root privileges.
- nano: Opens a file in the Nano text editor.
- /etc/ftpusers: File that contains the list of all disabled users.
❸ Provide the password (if necessary).❹ Now add the user who you want to disable:
ftp_user
❺ Now launch a Ubuntu Terminal on your client computer and execute the following command to access the FTP server:
ftp [email protected]
- ftp: Command to access the FTP server.
- ftp_user: Name of the user.
- 192.168.235.129: IP address of the server.
❻ Give the password associated with the user.You should see a “Login failed” message. Thus the user is disabled now.
- How to Create Multiple Users in Linux? [2 Methods]
- Create a User in Ubuntu as Read-Only Access to Log Folder
- How to Create User Account in Ubuntu with Public Key
- Create A User in Ubuntu that Runs a Script and Logs Out [4 Steps]
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
Relaed Articles
- How to Create User and Add to Sudo in Ubuntu? [2 Methods]
- 2 Ways to Create a User With Access to a Drive in Ubuntu
- How to Create a New User in Ubuntu by GUI? [Step-by-Step]
- 2 Ways to Create User Account in Ubuntu Using Terminal
- How to Create Home Directory for Existing User in Ubuntu
- Create User with UID and GID in Ubuntu? [3 Scenarios]
- How to Create a Sudo User in Ubuntu? [Step-by-Step]