Table of Contents
1. Commonly used configuration files
1.1 /etc/password file
Username: Encrypted password: Last modification time: Minimum time interval: Maximum time interval: Warning time: Account idle time: Expiration time:
useradd -g webadmin -G root,web -c 'test suer' bob
3. Other commands:
4. Case: Authorize the safeware directory to jack and mary Have write permission
5. Extension (RedHead series)
5.1 Add users in batches
5.2 Restrict user su to root
5.3 Replace with sudo su

User management in Linux system

Aug 02, 2017 pm 04:08 PM
linux user manage

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.

UID user ID number.

GID The user's primary group ID number.

                                                                                                                                                                                                          GECOS    Typically, it contains the user's full name.

directory The user's $HOME directory.

shell The program to run at login (if empty, use /bin/sh if set For a non-existent execution (program), the user cannot log in through login(1).)

1.1.1 User classification


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

root:# 21312sd$44:wd323%cds:14945:0:99999:7:::

Username: Encrypted password: Last modification time: Minimum time interval: Maximum time interval: Warning time: Account idle time: Expiration time:


1.3 /etc/group file

vim /etc/group

sudo:x:27:web,yanghuang,zhoumin,duyp,taofh,luanqq


group_name:password:GID:user_list
(Group name:Group password:Group ID:Group members)




2. Common commands:

Add a user: useradd [-ugGdsce] user name

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

<1> 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 < user. info

<2> The pwunconv command cancels the shadow password function

pwunconv

<3> 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
<4> 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&#39;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 "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles