In Linux, you have the privilege to manage different users on the same machine. Sometimes you want to give some specified access to some users in Linux. You might want to create a user without a home directory in Ubuntu to restrict the user’s access or limit their privileges. This article will help you to do it very smoothly.
Key Takeaways
- Learning to create a user without a home directory using Command Line Interface (CLI) in 3 simple steps.
- Getting familiar with sudo, useradd, su, passwd, getent, grep, userdel and a few other commands in Linux.
Requirements
- To change or modify file or folder permissions in Ubuntu, you must either be the root user or have root/sudo privileges.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
3 Steps to Create a User without Home Directory in Ubuntu
In Ubuntu, you can easily create new users from both the CLI(Command Line Interface) and GUI(Graphical User Interface). The distribution provides two different commands to create a new user. Here, I will use the useradd command only as the adduser command creates a home directory by default with the new user.
Read More: How to Create a New SFTP User in Ubuntu with a New SSH Key
Step 1: Create a New User in Ubuntu
You can create a new user from the terminal using the useradd command. Here, I have used the first command. Go through the below steps, to see how it works.
Steps to Follow >
➊ First launch a Ubuntu Terminal by pressing CTRL+ALT+T.
❷ Insert the following command to create a user:
sudo useradd -M abir
OR,
sudo useradd --no-create-home abir
- sudo: Grants administrative privileges.
- useradd: Adds a new user
- -M / –no-create-home: Skips creating a home directory for the new user.
- abir: Creates a new user named abir.
It will ask for the current user’s password.
➌ Press the ENTER key after providing the password.In the above image, you can see that nothing happens after giving the password. You need to set the password of the new user to create it successfully.
Step 2: Set the Password for the New User in Ubuntu
In this step, set the password for the new user ID. To do so follow the steps given below:
Steps to Follow >
➊ First, open your terminal.
➋ Then type the following command in your command prompt:
sudo passwd abir
- sudo: Grants administrative privileges.
- passwd: Sets/Changes password.
- abir: Name of the user to be created.
➌ Finally, press the ENTER button. Now, give your current user password.
Then, type the password for the new user ID and retype the password again.As you can see in the above image, my password is updated successfully.
Try to set a unique and strong password. Otherwise, you will get a warning message such as “BAD PASSWORD” as in the above image.
Step 3: Check for New User’s Home Directory in Ubuntu
Finally, to check whether the new user account has a home directory or not you need to switch to the new user. Follow the below procedure to do the same:
Steps to Follow >
➊ First, launch your terminal.
➋ Then type the following command in your command prompt:
su - abir
- su: Substitutes User ID.
- abir: Newly created user name to switch to.
➌ After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture.You can see that a warning message is displayed on the screen. It says no home directory is created for the new account.
- How to Create Group and Add User in Ubuntu? [2 Cases]
- Create Multiple Users in Linux? [2 Methods]
- How to Create a New User in Ubuntu by GUI? [Step-by-Step]
- Create a Sudo User in Ubuntu? [Step-by-Step]
Complementary Information
In addition to the specified methods of creating a new user without a home directory, these supplementary tasks are helpful as well.
Check If the Newly Created User Exists in Ubuntu
To check whether a new user account is created, you can apply the given approach. Here, I will check if the newly created user “abir” exists on my system. You can do so by following the given steps.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Then, type the following command into the command prompt.
getent passwd | grep abir
➌ Press ENTER.You can see in the above picture that a new user named abir has been created.
The output of the above image represents the following:
abir: Name of the user account.
x: Password field in a non-readable format ‘x’. which means that the password is stored in the /etc/shadow file.
1001: The user ID (UID) for this user.
1001: The group ID (GID) for this user.
,,,: Comment field. These three consecutive commas mean that for this user it is empty.
/home/tom: Home directory of this user.
/bin/sh: Default log-in shell of this user.
Give Root Privileges to an Existing User in Ubuntu
If you’re a root user or you’ve root privileges in Ubuntu, you can give root privileges to another existing user by adding it to the sudo group. For this, you have to use the usermod command in Linux. To do so follow the given instructions.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Then, type the following command into the command prompt.
sudo usermod -aG sudo abir
- sudo: Grants administrative privileges.
- usermod: Modifies an existing user account.
- -aG: Adds a user to the specific group.
- abir: Username of the user to be given root privileges.
➌ Press ENTER.
➍ After that, provide the password of the currently logged-in user.
➎ To check whether the user is added to the sudo group run the following command.
groups abir
➏ Press ENTER again.In the above image, you can see that I have given the user “abir” root privileges by adding it to the sudo group. Furthermore, I checked its group by using the groups command and tested its elevated powers by using the ls command.
- How to Create a New SFTP User in Ubuntu with a New SSH Key
- How to Create a User in Docker Container Without Docker File?
- How to Create User and Add to Sudo in Ubuntu? [2 Methods]
Delete User in Linux
You can easily remove any user from the system using the terminal with the userdel command in Ubuntu. Here, I will delete the user account named “abir”. To do the same follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, type the following command into the command prompt.
sudo userdel abir
- sudo: Grants administrative privileges.
- userdel: Deletes a user account.
- abir: Username of the user to be deleted.
➌ Press ENTER.
➍ Finally, provide the password of the currently logged-in user.In the above image, you can see that I removed the user “abir” using the Ubuntu terminal.
Conclusion
After completing this article, you will be able to create a user without a home directory very easily in Ubuntu. This will help you to organize your work making you a power user of Linux.
People Also Ask
What is the home directory of a user in Linux?
How does the home directory work?
Why home directory is used in Linux?
What is the purpose of a home directory in Linux?
Which character represents the user’s home directory?
What permission should the home directory have?
Where are user home directories stored in Linux?
What is the difference between the home directory and the root directory?
Related Articles
- How to Create a Jenkins User on Ubuntu? [2 Methods]
- Create MySQL User in Ubuntu? [2 Cases]
- How to Create FTP User for Specific Directory in Ubuntu [4 Steps]
- 2 Ways to Create a User With Access to a Drive in Ubuntu
- How to Create User with UID and GID in Ubuntu? [3 Scenarios]
- Create A User in Ubuntu that Runs a Script and Logs Out [4 Steps]