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.

- 36,264
- 56
- 94
- 147

- 7,382
-
1I just found this http://www.howtogeek.com/howto/ubuntu/add-a-user-on-ubuntu-server/ – Owais Lone Mar 07 '11 at 10:02
6 Answers
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.

- 149

- 2,942
-
6
-
3
-
24I believe the best practice is using
/sbin/nologin
as the login shell, although, using/bin/false
wouldn't make any differences. – Meow Oct 12 '15 at 14:49
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...".

- 117,780

- 4,957
-
7I actually didn't notice that this is
adduser
vs.useradd
, and running the commanduseradd
with these options did not produce any error, but created the account with shell/bin/bash
. "Buyer Beware". – isapir Oct 23 '16 at 20:01 -
1in centos7, group is not created by defaulty. ref: [root@srvr0 ava]# adduser --system --no-create-home --group bigdata adduser: group 'bigdata' does not exist – AVA Feb 09 '20 at 08:00
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.

- 229
- 2
- 2
-
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 – AVA Feb 09 '20 at 07:59
To add user without home directory the commands are,
useradd -M username
or
useradd --no-create-home username
or
adduser -M username
or
adduser --no-create-home username

- 13,462

- 61
Creating a User without Password with Home directory:
User & Group
Create the desired Group and User with Home-Dir.
mkdir <HOME-DIR>
sudo adduser --disabled-password --home <HOME-DIR> --group <GROUP-NAME>
sudo useradd -s /bin/bash -d <HOME-DIR> -g <GROUP-NAME> <USER-NAME>
Permissions
sudo chown <USER>:<USER> -R <HOME-DIR> # Owner permissions
sudo chmod 775 -R <HOME-PATH> # Optional
Add your primary user to the new group (Optional)
sudo usermod -a -G <GROUP-NAME> <PRIMARY-USER-NAME>
To see all the groups, use: $ id
, $ groups
. login to a user: $ sudo su - <USER>
. Re-login or Reset-PC is required.
Remove User and Group
sudo deluser --remove-home <USER-NAME>

- 4,920
try this command:
sudo useradd vivek
This will create a user without creating your home folder at /home/vivek

- 16,185
-
4No, as long as you are logged in with this account, the
/home/vivek
will be automatically created. – Meow Oct 12 '15 at 14:41