User information file: /etc/password
Password file: /etc/shadow
User group file: /etc/group
User group password file :/etc/gshadow
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
1.3 /etc/group file
group_name:password:GID:user_list
(Group name:Group password:Group ID:Group members)
2. Common commands:
-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
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
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
<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'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 "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
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
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!