Linux User Administration

You can add a user in Linux with the following command:

sudo useradd USERNAME

If no additional parameters are specified in the command when creating the user, then the default parameters are used. You can view the standard parameters with the command:

useradd -D

You can change the default settings with the command:

useradd -D PARAMETERS

Briefly describe the possible parameters when creating a user:
-b (The base directory, the directory in which the user’s home folder will be created, by default this is /home)
-s (Comment)
-d (Name of the home directory, by default the name of the user being created)
-e (Date in the format YYYY-MM-DD, after which the user will be disconnected. Standardly disabled)
-f (If the value is 0, then the record is blocked after the password is expired, with -1 it is not blocked. The default is -1)
-g (User group, you can specify the group name or GID. If you do not specify a parameter, a new group will be created whose name will be the same as the user name)
-G (List of groups the user will be in)
-k (Directory of templates to be placed in the user’s home folder. Default /etc/skel)
-m (Indicates that you need to create a home folder. By default, it is not created)
-p (Password. Not specified by default)
-s (Shell used by the user. Default /bin/sh)
-u (Manual UID to the user)

You can change the user password with the command:

sudo passwd USERNAME

Or just “passwd” if you need to change the password of the current user.

Briefly describe the possible keys when changing the user password:
-d (Delete user password)
-e (Makes the password obsolete and the next time the user logs in, the user will need to change it)
-i (Lock the user account when the specified number of days have passed since the password expired)
-n (Minimum number of days between password changes)
-x (Maximum number of days after which a password must be changed)

User parameters can be changed with the command:

sudo usermod USERNAME PARAMETERS

You can delete a user with the following command:

userdel USERNAME

When deleting, you can use the keys:
-f (Force user deletion, even if he is currently logged in)
-r (Delete user home directory)

You can create a group with the following command:

sudo groupadd GROUPNAME

The following keys can be used:
-g (Setting your own GID)
-p (Set group password)
-r (Create a system group)

The group is changed with the following command:

sudo groupmod PARAMETERS

List of possible keys:
-g (Install another GID)
-n (Rename, after the key the new group name is indicated, then the old one)
-p (Change group password)

You can delete a group with the command:

sudo groupdel GROUPNAME

Here are a few examples of other commands.
Switch to the root user session:

sudo -s -H
sudo -i

Switch to the specified user session:

sudo su USERNAME

End of session:

exit
Ctrl+D

Root user lock:

sudo passwd -l root

Unlock root:

sudo passwd -u root

Ending a sudo session:

sudo -K

List of last logged in users:

last

Display of users in the system:

who

Display current user name:

whoami

Display of users in the system and what they are doing:

w

List of connected users:

users

List of user groups:

groups USERNAME

Example of adding a user to the “sudo” group:

sudo usermod -a -G sudo USERNAME

User parameters are stored in the file /etc/passwd, group parameters in /etc/group, encrypted passwords in /etc/shadow.

See also my article:
Configuring the Network in Linux

Leave a comment

Leave a Reply