Create User Without Home Directory in Ubuntu in Just 3 Steps

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

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS

general process to create user without home directory in ubuntu

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

You can read the Complementary Information to know more about related topics.

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
explanation
  • 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.Create a user in UbuntuIn 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
explanation
  • 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.set password for newly created user in UbuntuAs 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
explanation
  • 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.switch user to check whether the user has home directory or notYou can see that a warning message is displayed on the screen. It says no home directory is created for the new account.



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
explanation
  • getent: Looks into the administrative database that is given as its argument.
  • passwd: Contains user information.
  • Pipe (|): Redirects the standard output.
  • grep: Looks for a specific pattern given to it as an argument.
  • abir: Username of the newly created user to be checked.

➌ Press ENTER.Check if the user is created without home directory in UbuntuYou can see in the above picture that a new user named abir has been created.

output analysis

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
explanation
  • 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.giving root privileges to user in UbuntuIn 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.



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
explanation
  • 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.delete user in UbuntuIn 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?

In Linux, home directory is the login directory for any specific user. It contains all the files, folders, documents and data of a user. This is the place where you will be after logging in first.

How does the home directory work?

The home directory in Linux is the warehouse of a user. Here every stuff of a user gets stored in. This is restricted only by the user and the root of the machine. Other than them no one has permission to do anything with these files.

Why home directory is used in Linux?

Home directly is used to store personal data, files, folders and documents of a user in the Linux operating system. The permission is restricted for others here.

What is the purpose of a home directory in Linux?

The purpose of home directory in Linux operating system is to store the private documents of a user. When you log in to the system you will be in your home directory in Linux environment.

Which character represents the user’s home directory?

The tilde (~) character represents the user’s home directory in Linux.

What permission should the home directory have?

In Linux the default permission for the home directory is dwrxr-xr-x. It means the owner has all the permissions, the group member and others have only read and execute permissions. They can not write the file.

Where are user home directories stored in Linux?

The user home directories are stored in /home/username/os location in Linux. Here, os means the operating system user is working with.

What is the difference between the home directory and the root directory?

Root directory is the top most directory. It is the parent directory of a home directory. The user and the root have the permission on home directory. In case of the root directory, only the root has the access to do anything.

Related Articles

5/5 - (11 votes)
Borhan Uddin

Borhan Uddin

Hello, I am Borhan Uddin, a resident of Dhaka, Bangladesh. I have completed my undergraduate degree in Electrical and Electronic Engineering (EEE) from Chittagong University of Engineering and Technology (CUET). I love to spend my leisure by playing and watching various movies & dramas. Currently, I am working as a Linux Content Developer Executive here. I would like to learn more about Linux every day of the week and would be keen to share it with you rapidly. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo