The Computer Oracle

How can I create a non-login user?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Realization

--

Chapters
00:00 How Can I Create A Non-Login User?
00:27 Accepted Answer Score 114
00:43 Answer 2 Score 308
01:10 Answer 3 Score 45
01:53 Answer 4 Score 34
02:25 Thank you

--

Full question
https://superuser.com/questions/77617/ho...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #useraccounts

#avk47



ANSWER 1

Score 308


You can use the following command:

useradd -r subversion

For more info, check manual pages with this command:

man useradd

You will find in this documentation the following flag that can be used for your purpose.

-r, --system                  create a system account

The -r flag will create a system user - one which does not have a password, a home dir and is unable to login.




ACCEPTED ANSWER

Score 114


You can use the -M switch (make sure it's a capital) to ensure no home directory will be created:

useradd -M subversion

then lock the account to prevent logging in:

usermod -L subversion



ANSWER 3

Score 45


Another solution to create a system user, using adduser :

adduser --system --no-create-home --group yourusername

You can remove --group if you don't need group yourusername, and --no-create-home if you do need a home for this user.

As mentionned by py4on in comments, on some systems one may need to use the --disabled-login option in order to, well, disable login for this user. It seems to be the default behaviour under Debian, though.

Beware that the numeric ID of the user will be of a system account. You can fix the uid using the --uid option, though.

Finally, note that on some systems (e.g. Fedora) adduser is a symlink to useradd, in which case this answer is not valid.




ANSWER 4

Score 34


The cleanest answer to the original question is to run the command:

adduser subversion --shell=/bin/false

And if you don't want the home directory either:

adduser subversion --shell=/bin/false --no-create-home

or, if you want an even more locked down system user (Normally this won't create a home directory - it has been reported that it will still create a home directory in linux mint as per comment below)

adduser subversion --system --group

All these commands will create a group with the same name as the user