Should I use useradd or adduser?

According to the manual you should use adduser:

man useradd

DESCRIPTION

useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.


Despite what the manpage says for useradd and userdel, I always use the low level back-end binaries: useradd, userdel, groupadd, groupdel.

The front-end scripts are interactive and meant to be user friendly, but do the same things. It is really a matter of personal preference.

In terms of practical differences:

useradd and groupadd have similar options to the commands usermod and groupmod, and there are no front-end scripts for these commands (i.e. no moduser or modgroup front-end scripts) so it is more consistent to use similar commands for account maintenance.

There are different config files for the default settings, like user IDs, shells, login groups, etc. So make sure you know which one you are editing to change the settings.

The front-end scripts "protect" you from entering stupid names, unless you supply the --force-badname option. For instance, usernames or group names that contain special characters, or that begin with a number. This is something that is unlikely to be done accidentally, so there is no need for the "protection."

The front-end scripts also "protect" you from deleting the root account, unless you use the --force option. Why anyone would be trying to use this, I don't know. It's also worth pointing out that you can't remove a user account if there is a running processes under it, and there is always processes running as root, so this should fail anyway.

(I've never had the courage to try, however.)

Only the front-end script adduser has an option to encrypt the home directory.

There are some things that the friendly scripts cannot do, however, and you would need to resort to the binary commands, though these are things you would normally not need to do:

  • useradd can override the default value of the skeleton home directory, without the need to edit the config file, or create a new config file. See the -k option.

  • useradd can prevent adding the newly created user to the lastlog database, with the -l option.

  • useradd and groupadd can create accounts with non-unique UIDs or GIDs, respectively, using the -o option. The scripts do not provide this capability.

  • useradd can create a new user with a selinux mapping, if selinux is enabled on the system, with the -Z option. This, however, can also be done with other commands once the account has been created, like semanage or usermod.

  • finally, and perhaps most importantly, only the binary commands have the ability to operate on alternate systems under an alternative root directory, like /snap/core, using the -R option.