In Linux systems, the concepts of users and groups are used to manage access permissions to files and processes.
User Account Information
User account information is primarily stored in the /etc/passwd file. This file contains basic information for all user accounts on the system, with each line corresponding to one user.
Each line in /etc/passwd consists of 7 fields separated by colons :.
[Username]:[Password]:[User ID (UID)]:[Group ID (GID)]:[Comment]:[Home Directory]:[Login Shell]
- Password: For security reasons, the actual password hash is not stored here directly. Instead,
xis displayed, and the password hash is stored in the/etc/shadowfile. The/etc/shadowfile is accessible only by the root user in read-only mode.
User Information Editing Commands
useradd: Adds a new user account.sudo useradd -m -s /bin/bash newuser # Create home directory and set bash as shell sudo passwd newuser # Set passwordusermod: Modifies an existing user account.sudo usermod -aG sudo newuser # Add newuser to the sudo group sudo usermod -l new_name old_name # Change usernameuserdel: Deletes a user account.sudo userdel -r olduser # Delete including home directorypasswd: Changes a user’s password.passwd # Change your own password sudo passwd username # Change another user's password (requires root privileges)
Group Account Information
Group account information is primarily stored in the /etc/group file. This file contains basic information for all groups on the system, with each line corresponding to one group.
Each line in /etc/group consists of 4 fields separated by colons :.
[Group Name]:[Password]:[Group ID (GID)]:[Members]
- Password: Group passwords are rarely used. Typically,
xis displayed. - Members: A comma-separated list of usernames belonging to the group.
Group Information Editing Commands
groupadd: Adds a new group.sudo groupadd newgroupgroupmod: Modifies an existing group.sudo groupmod -n new_group_name old_group_name # Change group namegroupdel: Deletes a group.sudo groupdel oldgroupid: Checks the groups that the current user belongs to.id # Example: uid=1000(username) gid=1000(username) groups=1000(username),4(adm),27(sudo)
Understanding and properly using these commands enables effective user and group management in Linux systems.