User Management Linux Command is a set of commands and utilities that are used to manage user accounts and permissions on a Linux system.
These commands allow system administrators to create, modify, delete, and manage user accounts, as well as control access to system resources and perform password authentication.
adduser
"adduser" is a command used in Linux to create a new user account. It prompts for information such as the new user's name, password, and default settings, and then creates the new user account. This command can only be run by a user with administrative privileges, such as root. The complete syntax for the adduser command is:
Options include --home to specify a custom home directory for the new user, --shell to specify a custom shell, --no-create-home to not create a home directory and others.
The created user can be further configured using other user management commands such as usermod and userdel.
For Examaple:
useradd
useradd is a Linux command used to add new users to the system. It creates a new account with the specified username, password, and other options, such as the default home directory, shell, and group membership.
Usage:
Options:
- -d, --home-dir: Specifies the user's home directory.
- -m, --create-home: Creates the user's home directory.
- -s, --shell: Specifies the user's default shell.
- -g, --gid: Specifies the user's primary group.
- -G, --groups: Specifies the user's additional groups.
- -c, --comment: Specifies the user's full name or other information.
usermod
usermod is a Linux command used to modify the attributes of an existing user account. Some of the attributes that can be modified using usermod include:- Login name
- User ID (UID)
- Group ID (GID)
- Home Directory
- Login shell
- Comment field (GECOS)
The basic syntax for usermod is:
Where username is the name of the user account you want to modify, and options specify the specific changes you want to make.
For example, to change the primary group of the user john to admin, you would use the following command:
userdel
The userdel command is used to delete a user account in a Linux system. This command removes the user's home directory, mail spool, and other files associated with the user, and also updates the system databases.
Syntax: userdel [options] username
Options:
- -r: removes the user's home directory and all its contents
- -f: force to delete user account even if it is in use or has files
Example:
Deletes the user account "newuser".
Deletes the user account "myusr" along with its home directory and its contents.
Note: It is advisable to use userdel with caution, as all user data will be permanently deleted and cannot be recovered.
passwd
passwd is a Linux command used to change a user's password.
Usage:
Options:
- -a, --all: report password status on all accounts
- -d, --delete: delete the password for the named account
- -e, --expire: immediately expire an account's password
- -h, --help: display this help message and exit
- -k, --keep-tokens: change password only if user token count is less than the minimum
- -l, --lock: lock the password for the named account
- -n, --minimum=MIN: set minimum number of days before password change to MIN
- -q, --quiet: quiet mode
- -r, --root: CHROOT_DIR directory to chroot into
- -u, --unlock: unlock the password for the named account
- -x, --maximum=MAX: set the maximum number of days before password change to MAX
Examples:
To change your own password: passwd
To change another user's password (as root): passwd <username>
Note: The behavior of passwd may vary depending on the system and distribution you are using.
chage
"chage" is a Linux command for changing user account aging information. It allows you to modify the password aging information for a user account, such as the number of days between password changes, the number of days after which the password must change, the minimum number of days between password changes, and the maximum number of days a password is valid.
Usage:
id
The "id" command is used to display the user and group information of a specified user or the current user if no username is provided. It displays the user ID (UID) and group ID (GID) numbers, as well as the user and group names, the number of supplementary groups the user is a member of, and the user's default security context.
The command has the following syntax:
Some common options are:
- -a: display all information about the user, including group and supplementary group information.
- -g: display only the group ID number.
- -u: display only the user ID number.
Example:
In this example, the command was executed without a specified username, so it displayed information about the current user. The output shows the UID and GID numbers, along with the names of the user and primary group, and the names of the supplementary groups of the user is a member of.
groups
The "groups" command displays the names of the groups a user is a member of. It takes the username as an argument and by default shows the group of the current user. The output is a list of group names separated by spaces.
Syntax:
- -a, --all: display groups of all users in the system, not just the current user
- -n, --numeric-id: display the numeric IDs of the groups instead of the group names
Example:
groups to display the groups of the current user. groups [username] to display the groups of a specific user.
su
"su" is a Linux command that stands for "switch user." It allows you to temporarily switch to another user account, either by specifying the username or by default to the root user. The "su" command is used to switch user context from the current user to another user.
Syntax:
- -c, --command=COMMAND: Run a command with specified arguments as the target user.
- -l, --login: Start a login shell with an environment similar to a real login.
- -m, --preserve-environment: Preserve the environment.
Example:
Switch to the root user account:
switch to the specified user account:
su -c '[command]' [username]: run a command as the specified user.
sudo
sudo is a Linux/Unix command that allows users to run programs with the security privileges of another user, usually the superuser. It is commonly used to perform administrative tasks.
The basic syntax for sudo is:
For example:
Here, the sudo command allows the user to run the apt-get update command with superuser privileges, which is necessary for updating the system packages.
Note that sudo requires a password for authentication, usually the password of the user who runs the sudo command. Also, the users who are allowed to use sudo are specified in the /etc/sudoers file, which can be edited using the visudo command.