How to create users in Linux with the generical useradd command

The useradd command is generical for all the Linux distros:

Watch Free Movies

Syntax: useradd [options] username

Creating users with the default configuration:

$ sudo useradd yoda
$ grep yoda /etc/passwd
yoda:x:1010:1012::/home/yoda:/bin/sh

To view the default options for creating users, use useradd -D . (the displayed output is for a debian based Linux)

$ useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no

This options differ from distro to distro. For example, the default login shell in Debian is /bin/sh and in Fedora is bash (/bin/bash).

To modify this options, you have to edit the /etc/default/useradd file.

Creating users with custom homedir and login shell with useradd -m -d /home/dir -s /bin/bash user:

$ sudo useradd -m -d /home/starwars -s /bin/bash anakin
$ grep anakin /etc/passwd
anakin:x:1006:1008::/home/starwars:/bin/bash

-m is for creating the homedir if it doesn’t exist and copy the data from the /etc/skel folder in the freshly new created dir. if the folder already exists, nothing will be copied from the /etc/skel dir. -d is for setting the home directory and -s is for choosing the login shell.

By default, the new user gets assigned the first UID available (not used) and added to a group.

Next the root needs to set up the new users password:
$ sudo passwd username
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Now you are able to create users in whatever Linux distro you want.

The Debian based distos have adduser, a user-friendly interactive tool for creating users and newusers, a command for creating a list of users simultaneously.
Read more about adding users in Debian based distros here.

Scroll to Top