1. Commonly used configuration files
User information file: /etc/password
Password file: /etc/shadow
User group file: /etc/group
User group password file :/etc/gshadow
1.1 /etc/password file
vim /etc/password
fubh:x:1020:1000::/home/fubh :/bin/bash
man 5 password #View configuration file help
(Password file) There is one record per line, and each line has this format:
account :password:UID:GID:GECOS:directory:shell
(Account:Password:User ID:Group ID:General information:Host directory:shell)
The field description is as follows:
Account users' name in the system, it cannot contain the cipher of the capital letters.
GID The user's primary group ID number.
directory The user's $HOME directory.
UID=0 is a super user
UID=500~ 60000 is an ordinary user
UID=1~499 It is a pseudo user (related to system and program services)
1.2 /etc/shadow file
Username: Encrypted password: Last modification time: Minimum time interval: Maximum time interval: Warning time: Account idle time: Expiration time:
1.3 /etc/group file
group_name:password:GID:user_list
(Group name:Group password:Group ID:Group members)
2. Common commands:
useradd -g webadmin -G root,web -c 'test suer' bob
-u UID-g Default user group GID
-G Specify that the user belongs to multiple groups
-d Host directory
-s Command parser Shell
-c Description information
-e Specify user expiration time
Settings Password: passwd Username
Modify user information:
Modify username: usermod -l New username Old username
Add user group: usermod -G sys bob_fu
Delete a user: userdel [-r] username (-r deletes the user's home directory)
Set a password for the group: gpasswd group name
gpasswd [-adArR] username group name
- a Add a user to a group
-d Delete the user from the group
-A Set the user group administrator
-r Delete the user group password
-R Prohibit the user from switching to regroup
For example:
gpasswd webadmin
gpasswd -a bob_fu webadmin
gpasswd -A bob_fu webadmin
gpasswd -r webadmin
Lock a user: passwd -l jack / usermod -L jack
Unlock a user: passwd -uf jack / usermod -U jack
Switch the group: newgrp webadmin
View the group: groups lisi
Add a group: groupadd [-g GID] Group name (View: grep webadmin /etc/group)
Delete group: groupdel webadmin
Rename group: groupmod -n New name Old name
3. Other commands:
pwck Detect /etc/passwd file (lock file)
vipw Edit /etc/passwd file view (lock file)
id View user id and group information
finger View user details
su Switch users (su - username)
passwd -S View user password status
who, w View current Denghu user information
grpck User group configuration file Detect
vigr Edit /etc/group file (lock file)
chage [-lmM] Set password (available under LINUX)
-l View user password settings chage -l jack
-m Password modification The minimum number of days
-M The maximum number of days for password modification
-d The date the password was last modified
-I The number of days to determine the account after the password expires
-E Set the password expiration date, if it is 0 , indicating that the password will expire immediately, if it is -1, it will never expire
-W Set the number of days to start warning before the password expires
4. Case: Authorize the safeware directory to jack and mary Have write permission
root creates a directory:
mkdir /software
Add two users:
useradd jack
useradd mary
Set password:
password jack
password mary
Add a group
groupadd softadm
Add user to group
usermod -G softadm jack
gpasswd -a mary softadm
View group members:
grep softadm /etc/group
Authorize the root group in the directory to the softadm group
chgrp softadm ./software
Give Add directory write permission to the group
chmod g+w ./software
5. Extension (RedHead series)
5.1 Add users in batches
The newusers command imports the user information file
For example, the content of user.info is as follows
test01::10001:503::/home/test01:/bin/bash
test02::10002:503:: /home/test02:/bin/bash
test03::10003:503::/home/test03:/bin/bash
test04::10004:503::/home/test04:/bin/bash
test05::10005:503::/home/test05:/bin/bash
test06::10006:503::/home/test06:/bin/bash
newusers
The pwunconv command cancels the shadow password function
pwunconv
The chpasswd command imports the password
For example, the content of pass.info is as follows
test01:admin+01
test02:admin+02
test03:admin+03
test04:admin+04
test05:admin+05
test06:admin+06
chpasswd
The pwconv command writes the password to the shadow file
pwconv
Optimization solution: write a script
#!/bin/bash #add-some-users.sh #The script is add some users to a new group. echo "Welcome to the add some users!" echo -n "Please input the new group(example : mygroup) : " read my_new_group groupadd $my_new_group echo -n "Add the $my_new_group group is successful!" echo "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" echo "Then add some users to the $my_new_group group!" echo -n "Please input the username(example: student) : " read new_user echo -n "Please input the username(begin_id)(example: 1 ) : " read begin_id echo -n "Please input the username(end_id)(example: 10 ) : " read end_id echo "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" for ((i=$begin_id;i<=$end_id;i++)) do #add the new_user to the my_new_group,and no add new_user's group useradd -n -g $my_new_group $new_user$i #delete the new_user password passwd -d $new_user$i chage -d 0 $new_user$i // done echo "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
5.2 Restrict user su to root
groupadd sugroup
chmod 4550 /bin/su
chgrp sugroup /bin.su
ls -l /bin/ After su
is set, only users in the sugroup group can use su to switch root
sueradd bob
passwd bob
usermod -G sugroup bob
5.3 Replace with sudo su
sudo configuration file/etc/sudoers
(Administrator) edit configuration file command:
visudo
Format: user name (group name) host address (host name )=command (absolute path)
For example:
User authorization: bob 192.186.9.3=/usr/sbin/useradd,/usr/sbin/userdel
Group authorization: %webadmin host1=/ bin/vim /etc/httpd/conf/httpd.conf
The above is the detailed content of User management in Linux system. For more information, please follow other related articles on the PHP Chinese website!

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor