Linux create user with no home directory

Debian: create a new user without home directory

Not really sure if you can create a user which doesn’t have a home directory specified. That being said, the specified home directory doesn’t have to exists. You can call the adduser with the option —no-create-home.

(adduser is usually the preferred higher level tool if called interactively.)

According to the man page of useradd(8) you either want to add the parameter -M to your useradd call or you want to set CREATE_HOME=no in /etc/default/useradd .

-M Do no create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes. 

On Debian based systems typically the adduser command is used to create new accounts instead of directly calling useradd .

The adduser option to skip creating a home directory is —no-create-home .

$ useradd joe $useradd -m joe does the opposite

Depending on the settings for $CREATE_HOME in /etc/default/useradd the second command certainly does not do the opposite…

ain’t you confusing -m and -M (in capitals) ? -m, —create-home The user’s home directory will be created if it does not exist. The files contained in SKEL_DIR will be copied to the home directory if the -k option is used, otherwise the files contained in /etc/skel will be used instead. Any directories contained in SKEL_DIR or /etc/skel will be created in the user’s home directory as well. The -k option is only valid in conjunction with the -m option. The default is to not create the directory and to not copy any files.

Источник

How do I add a user in Linux without a home directory?

While managing users, Linux administrators need to manage different types of users based on the privileges he/she wants to set. User management includes access control and Group management of the user. It is often seen that when we create users in Linux, there are two types of commands available useradd and adduser. We will add a user in Linux without a home directory using the useradd command in this post.

useradd Command

The useradd is a command used for creating a user in any Linux-based operating system. It is a low-level or less secure command for creating a user because it only creates a user until we specify a flag.

This command does not automatically create a home directory until a -m flag is specified.

Читайте также:  Medusa in kali linux

Without a Home Directory flag

Moreover, this command also provides a flag or option if you do not want to create a home directory of a user while creating a user.

-M for creating a user without a Home directory
–no-create-home is also used for not creating a home directory of a user

Let’s do some practical, create users using the useradd command and witness it.

Create a user using the useradd Command

To create a user using the useradd command, type the command given below:

In the above command, Ivan is the username, so provide your username at the place of Ivan.

You can witness in the screenshot attached; the user is created without asking for any password.

To create a password for this user, execute the command given below:

Type the new password you want to set for the user:

After successfully creating a user and setting its password, log in to the user profile using the command given below:

Type the recently created password for the newly created user:

You can see we are logged in to Ivan’s shell, and you can also witness that the user does not have the home directory.

Wrap Up

User management is an extremely responsible task for any Linux administrator. Due to the security reasons and privileges of the users, Linux administrators have to create some users without a home directory. This article provides to-the-point detail for creating a user without a home directory.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.

Источник

How to add a user without /home?

I want to create a new user to run a service on the system but don’t want to have /home and other configuration files for it. Like there is a user for postgres but it doesn’t have any /home directory.

6 Answers 6

By default the command useradd doesn’t create home directories, but for a daemon I recommend you to use the system option and change the shell to a non-existent one so no one can login with said account (in ssh for example):

sudo useradd -r -s /bin/false USERNAME 

You can see all the options with man useradd and man groupadd if you want to create a group for the user too.

I believe the best practice is using /sbin/nologin as the login shell, although, using /bin/false wouldn’t make any differences.

Try adduser —system —no-create-home USERNAME or simply have a look at the man adduser which claims to be a «friendlier front end to the low level tools like useradd. «.

I actually didn’t notice that this is adduser vs. useradd , and running the command useradd with these options did not produce any error, but created the account with shell /bin/bash . «Buyer Beware».

Читайте также:  Linux выполнить скрипт при загрузке

in centos7, group is not created by defaulty. ref: [root@srvr0 ava]# adduser —system —no-create-home —group bigdata adduser: group ‘bigdata’ does not exist

I needed something similar — a new user without login privileges and tied to a system service. However, the answer by Clausi creates a user with the primary group as ‘nogroup’, which wasn’t really desirable.

adduser —system —no-create-home —group USERNAME creates a system group with the same name as the user and associates it with the user as the primary group. This can then be verified by using the groups USERNAME or the id USERNAME command.

in centos7, group is not created by defaulty. ref: [root@srvr0 ava]# adduser —system —no-create-home —group bigdata adduser: group ‘bigdata’ does not exist

Источник

Adding a New User in Linux

Adding a new linux user

One of the most basic functions for any Linux Administrator is the creation of user accounts, so understanding the Linux “ useradd ” command functionality is a basic requirement for anyone to know. The command is a low-level utility used for adding/creating user accounts in Linux operating systems and is similar to “useradd” command. As a note of caution, there are some differences in the functionality of the “useradd” command, so it is you to read your documentation, before using our instructions to create new user accounts in Linux. When the ‘useradd‘ command is executed, there are 3 major consequences:

  • Modification of /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files associated with the newly created user account.
  • Creation of the home directory for the new user.
  • Setting of permissions/ownerships associated with the home directory.

The syntax of the “useradd” command is:

Read on as we review and explain the most used useradd commands with their practical examples in Linux.

Basic Usage of useradd Commands

useradd: Adding a New User in Linux

To add/create a new user, simply follow the command “useradd” (or “adduser” command) with a “username” which is an identifier used by an individual to login into the system. Each username must be unique and distinct from other usernames already on the system. In order to add a new user called “testuser”, as a “root” user, enter the following commands:

Using the useradd passwd commands linux

As seen in the screenshot above, when adding a new user in Linux with ‘useradd‘ command (vs the “adduser” command. Why we need both in Linux, I have no clue, it was probably as a result of some typical nerd software fight.), it gets created in locked state until you set a password for that account with “ passwd ” command. Upon creation of a new user , its data is added to the the “/etc/passwd” file, which is used to store users information

new user added to /etc/passwd file

The entry in the /etc/passwd” file contains a set of seven colon-separated fields:

Читайте также:  Linux timeshift восстановление системы

Username : Used to login into system. Ranges between 1 to 32 charcters long;
Password : User password (or x character) that is encrypted and stored in “/etc/shadow;
User ID (UID) : Every user has a User Identification Number ( UID ). By default UID 0 is reserved for root user, UID’s from 1 to 99 are reserved for predefined accounts, and UID’s ranging from 100-999 are reserved for system accounts and groups.
Group ID (GID) : The primary Group ID (GID) Group Identification Number stored in /etc/group file.
User Info : This field is optional and allows you to define extra information about the user and if not filled out, remains blank, so you will see “::” in the listing.
Home Directory : The absolute location of user’s home directory.
Shell : The absolute location of a user’s shell i.e. /bin/bash.

Create a User with Different Home Directory

As a default, the “useradd” command creates a user’s home directory under /home directory with username. You can modify this action with the “-d” option in conjunction with the location of a new home directory (i.e. /home/top_secret_projects). For example, the following command will create a user “testuser_1” with a home directory “/home/top_secret_projects” as seen in the screen shot below:

adding a new linux user with different default directory

Create a User with Specific User ID

Every Linux user has its own UID and by default, it assigns UID’s in sequence (1001, 1002, etc). Linux provides an option to override this sequence with the “-u” option (Make sure the new UID is unique from any existing users on the system):

Custom UID

Create a User with Specific Group ID

By design, every user is assign its own Group Identification Number ( GID ). Using the “-g” option, you can create users with specific GID’s.

Here in this example, we will add a user ‘testuser_3‘ with a GID of 9999. Notice how the UID increment from the last user’s UID of 9999:

adding user with custom GID

Add a User to Multiple Groups

If you are wanting to add a user to multiple groups, make use of the “ -G ” when adding a new user. Make sure that each group name is separated by a comma, with no intervening spaces.

Here in this example, we are adding testuser_4 user into multiple groups like admins, webadmin and developer.

[root@kali ~]# useradd -G admins,security,developers testuser_4

Next, verify that the multiple groups assigned to the user with id command.

[root@kali ~]# id testuser_4

uid=1001(testuser_4) gid=1001(tecmint)
groups=1001(testuser_4),501(admin),502(security),502(developers)

Add a User without Home Directory

In some situations, we may not want to assign a home directory when we create a new user, but be aware that there could be some security ramifications associated with this: To create this user, make use of the “-M” option in conjunction with the “adduser” command and then verify that its home directory does not exist, as shown in the screenshot below:

Источник

Оцените статью
Adblock
detector