User Management Linux Command

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:

adduser [Options] username

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:

username@Technoscience:~$ sudo adduser myuser
[sudo] password for username:
Adding user `myuser' ...
Adding new group `myuser' (1001) ...
Adding new user `myuser' (1001) with group `myuser' ...
Creating home directory `/home/myuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for myuser
Enter the new value, or press ENTER for the default
Full Name []: My User
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
username@Technoscience:~$

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:

useradd [OPTIONS] USERNAME

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.
For a complete list of options and more details on using useradd, refer to the man pages.

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:

usermod [options] username

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:

username@TechnoScience:~$ usermod -g admin myuser
For more information and usage options, refer to the man page for usermod by typing man usermod in the terminal.


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

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".

username@TechnoScience:~$ sudo userdel newuser
username@TechnoScience:~$

Deletes the user account "myusr" along with its home directory and its contents.

username@TechnoScience:~$ sudo userdel -r myuser

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:

passwd [OPTION]...[USER]

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

username@TechnoScience:~$ sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
username@TechnoScience:~$

To change another user's password (as root): passwd <username>

username@TechnoScience:~$ sudo passwd newuser
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
username@TechnoScience:~$

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: 

chage [-l] [-d LAST_DAY] [-E EXPIRE_DATE] [-I INACTIVE_DAYS] [-m MIN_DAYS] [-M MAX_DAYS] [-W WARN_DAYS] username


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:

id [OPTIONS][USERNAME]

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:

username@TechnoScience:~$ id
uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),111(lpadmin),112(sambashare)
username@TechnoScience:~$

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:

groups [OPTION] [USERNAME]
Options:
  • -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.

username@TechnoScience:~$ groups
username adm cdrom sudo dip plugdev lpadmin sambashare
username@TechnoScience:~$


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: 

su [OPTION][USERNAME]


Options: 
  • -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:

username@TechnoScience:~$ su
Password:
root@TechnoScience:/home/username$

switch to the specified user account:

username@TechnoScience:~$ su myuser
Password:
myuser@TechnoScience:/home/username$

su -c '[command]' [username]: run a command as the specified user.

myuser@TechnoScience:/home/username$ su -c pwd username
Password:
/home/username
myuser@TechnoScience:/home/username$


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:

sudo [command]

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.

username@TechnoScience:~$ sudo apt-get update

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.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!