FUNDAMENTALS A Complete Guide for Beginners
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:
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:
- At first, open a Terminal in Ubuntu.
- 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.
- 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.
Here’s an step-by-step guide to setup an FTP server:
- First, press CTRL+ALT+T to launch an Ubuntu Terminal.
- Now write the command below to update the system:
sudo apt-get update
EXPLANATION- 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
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.EXPLANATION- 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
EXPLANATION- nano: Opens a file in the Nano text editor.
- /etc/vsftpd.conf: Configuration file for “vsftpd”.
- 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.
- Press CTRL+O and ENTER to save; CTRL+X to exist.
- 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.
- Use the following two commands to restart the FTP server and see its status:
sudo systemctl restart vsftpd
sudo systemctl status vsftpd
Your server is up and running if you see “active (running)” as in the image above. Well done!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.
- 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.
The IP address of my server is 192.168.235.129.Note: If your system doesn’t have “ifconfig”, use the following command to install itsudo 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:
- 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
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”.
- 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”.
- Now insert the command below to create the “user_config_dir” directory 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.
- Execute the following command to create and open a file:
sudo nano /etc/vsftpd/user_config_dir/ftp_user
Here 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.EXPLANATION- nano: Opens a file in the Nano text editor.
- /etc/vsftpd/user_config_dir/ftp_user: “ftp_user” file in the user configuration directory.
Note: The filename should be similar to the username. - 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”.
- 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.
- 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.
- 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.
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:
- Launch Ubuntu on your client computer.
- 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.
- Provide the password associated with the user.
- Write the following command to print the current path:
pwd
In the output, you can see the current path is “/var/ftp/ftp_user” which we have defined earlier.EXPLANATION- 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]
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:
- At the beginning, open a Terminal in Ubuntu.
- 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”.
- 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.
- 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.
- 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.
- Then try to change your directory like the below:
cd /etc
It is showing “Failed to change directory”, that means the user is restricted to its home directory.EXPLANATION- 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:
- Launch a Ubuntu Terminal by pressing CTRL+ALT+T.
- Open the “ftpusers” file using the command below:
sudo nano /etc/ftpusers
EXPLANATION- /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]
EXPLANATION- 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
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
- 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]
Wow. Thank you for such a detailed tutorial on this.
Super helpful!