Linux user management (useradd, userdel, usermod)

Learn how to create, delete and modify a user in Linux (useradd, userdel, usermod). Basic user management which is must know for every Linux/Unix administrator.

Anyone accessing system locally or remotely has to has a user session on the server hence can be termed as a user. In this post, we will be seeing user management which is almost similar for all Linux, Unix systems. There are three commands useradd, userdel and usermod which are used to manage users on Linux systems.

Command: useradd

Command to add a new user to the system. This command can be as short as just one argument of userid. When running with just userid as an argument then it takes all default values for creating that user as defined in /etc/default/useradd file. Or else a number of options can be specified which defines parameters of this new user while creation.

See the above example with and without using options. Also, check the below list, it shows where you can verify the account-related particular parameter which you specified in useradd command.

home_dir Check using ls -lrt

uid, gid In /etc/passwd and /etc/group

comment, shell In /etc/passwd file

groups In /etc/group file

skel_dir files Check-in home_dir

expire_date, inactive Check-in chage -l username output.

Encrypted password In /etc/shadow file

Command: userdel

As the name suggests its a command to delete users. It has only two options –

-r Remove user’s home_dir & mail spool

-f Removes user even if he/she logged in. Removes home_dir, mail spool & group of the same name even these are being shared by another user. Dangerous!

If none of the options used and command just ran with userid argument. It will only remove the user from the system keeping its home_dir, mail spool and a group of the same name (if any) intact on the server.