GO KALI FREE
User Management

useradd Linux Command

Creates a new user account on the system.

What does useradd do?

Creates a new user account on the system.

Syntax

useradd [options] username

Practical example

sudo useradd -m -s /bin/bash john

Questions about useradd

How do I create a user with a home directory?

Use `sudo useradd -m username` to create a user with a home directory. The `-m` flag creates /home/username automatically.

How do I create a user with a specific shell?

Use `sudo useradd -s /bin/bash username` to set the login shell. Common shells are `/bin/bash`, `/bin/sh`, or `/bin/zsh`.

How do I create a user and set a password?

Create the user with `sudo useradd -m username`, then set a password with `sudo passwd username`.

How do I create a user in a specific group?

Use `sudo useradd -m -G groupname username` to add the user to a secondary group. Use `-g` for the primary group.

What is the difference between useradd and adduser?

`useradd` is the low-level command with fewer defaults. `adduser` is a friendlier wrapper that asks interactive questions and sets up more defaults.

How do I create a system user?

Use `sudo useradd -r -s /usr/sbin/nologin username` to create a system user for services. The `-r` flag assigns a UID in the system range.

How do I set an expiry date for a user account?

Use `sudo useradd -e 2025-12-31 username` to set an account expiration date. The account will be disabled after that date.

How do I see the default settings for useradd?

Use `useradd -D` to view and modify default settings like the default shell, home directory location, and password expiry.

Related User Management

passwd

Changes the password for a user account.

usermod

Modifies an existing user account (groups, shell, home directory, etc.).

sudo

Executes a command with superuser (root) privileges.

userdel

Deletes a user account. Use -r to also remove the home directory.

su

Switches to another user account or the root user.

groupadd

Creates a new group on the system.