212

I'd like to create a user and a group both called subversion on a RHEL 5 system. I looked at the man page for useradd and I guess the command would be just be...

useradd subversion

However, not sure how to avoid creating a home dir. Also, I don't want it to be a user that can log in to the system.

The main purpose is just to provide an owner for a SVN repository.

ᔕᖺᘎᕊ
  • 6,393
Ethan
  • 3,921

9 Answers9

313

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.

galoget
  • 403
rynop
  • 3,238
116

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
49

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.

36

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

TimmyGee
  • 461
31

The safest form of doing this would be to use adduser like so:

$ adduser -r -s /bin/nologin subversion

NOTE: Be sure to include -s /sbin/nologin to disable any login shell from being made available to the account.

Confirmation of setup

$ grep subversion /etc/passwd /etc/shadow
/etc/passwd:subversion:x:496:496::/home/subversion:/bin/nologin
/etc/shadow:subversion:!!:17232::::::

However there's no directory:

$ ll /home | grep subversion
$

Confirm that the account is otherwise usable:

$ sudo -u subversion whoami
subversion

$ sudo -u subversion date
Tue Mar  7 08:58:57 EST 2017

Removal

If you need to remove this account:

$ userdel subversion -r
userdel: subversion mail spool (/var/spool/mail/subversion) not found
userdel: subversion home directory (/home/subversion) not found
$

And confirm:

$ grep rtim-hc-user /etc/passwd /etc/shadow
$
slm
  • 10,859
8

In Debian, you could create a system user (without home directory) and login shell:

useradd --system --shell=/usr/sbin/nologin <username>

If your nologin program is in /sbin/nologin, please change accordingly.

yoonghm
  • 191
3

On a CentOS 7 machine you can use the following commands:

  • If the user does not exist:

    useradd testuser --shell=/sbin/nologin
    
  • if you want to modify an existing user:

    usermod testuser --shell=/sbin/nologin
    
galoget
  • 403
0

Start by generating an encrypted password for the user with a maximum of 8 characters long by doing:

openssl passwd -crypt new_password_less_than_eight_chars_long

Then you do:

useradd -m -g groupname -G otherGroupsSeperatedByComma -p encryptedPassword username
zx485
  • 2,337
0
useradd -s /sbin/nologin -M subversion

-s, set shell as /sbin/nologin - which will set user nologin accesss

-M, do not create users home directory

Raj
  • 1
  • 1