1. User and group management
(1) Create a common user: useradd [username]
(2) Modify user UID: usermod -u [new_UID] [username]
(3) Modify user password and validity period and other information: sudo change [option] [username]
(4) Create a system user: sudo useradd -r [username]
(5) View configuration files /etc/passwd and /etc/shadow: cat /etc/passwd, cat /etc/shadow;
grep [username] /etc/passwd, grep [username] /etc/shadow
2. Operations such as group creation and modification
(1) Create a new group: groupadd [groupname]
(2) Modify the group account name and GID: groupmod -n [newgroupname] [groupname];
groupmod -g [newGID] [groupname]
(3) View the groups the user belongs to: groups [username]
(4) Add the user to the newly created group: usermod -aG [groupname] [username]
(5) Delete the user from the group: gpasswd -d [username] [groupname]
(6) View configuration files /etc/group and /etc/gshadow: cat /etc/group, cat /etc/gshadow
3. Comprehensive application: create user accounts and corresponding group accounts, and create working directories for each user.
(1) Create a group:
Suppose the company has 6 departments, namely A, B, C, D, E, and F. You can create groups for each department with the following command:
sudo groupadd group_A
sudo groupadd group_B
sudo groupadd group_C
sudo groupadd group_D
sudo groupadd group_E
sudo groupadd group_F
(2) Create a user:
For each department, you need to create accounts for each employee in it. Taking department A as an example, you can use the following command to create accounts for two employees in department A:
sudo useradd user_A1
sudo passwd user_A1 // Set a password for the user
sudo useradd user_A2
sudo passwd user_A2 // Set a password for the user
For other departments, you can repeat the above steps.
(3) Add the user to the group:
Next, you need to add each user to their department's group. Taking department A as an example, users A1 and A2 can be added to the group group_A with the following command:
sudo usermod -a -G group_A user_A1
sudo usermod -a -G group_A user_A2
For other departments, you can repeat the above steps.
(3) Create the user's working directory:
Finally, you need to create a working directory for each user and assign its ownership to that user and the group they are a part of. Taking user A1 as an example, you can use the following command to create a working directory for it:
sudo mkdir /home/user_A1
sudo chown user_A1:group_A /home/user_A1
For other users, you can repeat the above steps.
Fourth, view the file system format
(1) View hard disk partition information: fdisk -l
(2) Check the file system type: df -T
(3) View U disk partition information: fdisk -l
(4) Manually mount the U disk: mount -t vfat /dev/sdb1 /mnt/usb
(5) Mount the ISO file: mount -o loop [filename.iso] [mountpoint]
5. Process management
(1) Use the ps command to view process information: ps aux
(2) Use the pipeline and less (more) command to view the process: ps aux | less
(3) Use the grep command to find the specified process: ps aux | grep [processname]
(4) Use the top command to dynamically display process information: top
(5) Use the top command to detect the status information of the specified process: top -p [pid]
6. Process state control
(1) Use the vi & command to start the process: vi &
(2) Use the ps command to view the PID of the vi process: ps aux | grep vi
(3) Use the kill command to end the process: kill [PID]
(4) Use the nice vi & command to start the process and observe the niceness value: nice vi &
(5) Use the nice vi --10 & command to start the process and set a negative niceness value: nice vi --10 &
(6) Use the renice command to adjust the niceness value: renice -n [new_niceness] [pid]
(7) Use killall to end all vi processes: killall vi