当前位置:网站首页>User and group management
User and group management
2022-07-23 05:59:00 【Pigs who love coriander】
One 、 User management
The user types :
- Super administrator root
- Ordinary users
- System users
- Ensure that the application can be used normally 、 function
- It is not allowed to log in to the system , There is security
User related files
1、/etc/passwd
Save user information
root:x:0:0:root:/root:/bin/bash
Format : user name : Password placeholder :uid:gid: explain : Home directory :shell
uid user ID
Administrators 0
System users 1----999
Ordinary users 1000+
shell to Linux Kernel translation commands
/bin/bash
Default shell, You can log in to the system normally 、 Carry out orders
/sbin/nologin
You are not allowed to log in to the system
2、/etc/shadow file
Save the user's password
Two 、 User management operations
1、 Create user
useradd [ Options ] user name
[[email protected] ~]# useradd user01
Common options :
-u Designated user ID
[[email protected] ~]# useradd -u 2022 user02
-s Specify the user's shell
-M Do not create the user's home directory
[[email protected] ~]# useradd -s /sbin/nologin -M nginx
[[email protected] ~]# useradd -u 2001 -s /sbin/nologin -M tomcat
-g Basic group
[[email protected] ~]# groupadd group1
[[email protected] ~]# useradd -g group1 apache
-G Additional group , Additional group , Additional group
[[email protected] ~]# groupadd nginx
[[email protected] ~]# groupadd httpd
[[email protected] ~]# groupadd tomcat
[[email protected] ~]#
[[email protected] ~]# useradd -G nginx,httpd,tomcat apache // Multiple additional groups are separated by commas
2、 Switching users
su - user name
[[email protected] ~]# su - apache
3、 Set user password
passwd [ Options ] [ user name ]
[[email protected] ~]# passwd // Change the current user password
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
// Change the password of the specified user , Only administrators root Can be successfully executed
[[email protected] ~]# passwd user01
-l Lock user password , Can't log in to the system
[[email protected] ~]# passwd -l user01
Locking password for user user01.
passwd: Success
-u Unlock user password
[[email protected] ~]# passwd -u user01
Unlocking password for user user01.
passwd: Success
-e Force user password expiration , You have to change your password the next time you log in
[[email protected] ~]# passwd -e user01
Expiring password for user user01.
passwd: Success
4、 To view the user ID Information
[[email protected] ~]# id apache
5、 Modify user information
usermod [ Options ] user name
-u Modify the user ID
[[email protected] ~]# id userA
uid=1003(userA) gid=1003(userA) groups=1003(userA)
[[email protected] ~]#
[[email protected] ~]# usermod -u 3000 userA
[[email protected] ~]# id userA
uid=3000(userA) gid=1003(userA) groups=1003(userA)
-s Modify the user shell
[[email protected] ~]# grep "userB" /etc/passwd
userB:x:1004:1004::/home/userB:/bin/bash
[[email protected] ~]# usermod -s /sbin/nologin userB
[[email protected] ~]# grep "userB" /etc/passwd
userB:x:1004:1004::/home/userB:/sbin/nologin
-G Additional group , Additional group Add users to additional groups
[[email protected] ~]# id userC
uid=2000(userC) gid=2000(userC) groups=2000(userC)
[[email protected] ~]# groupadd caiwu
[[email protected] ~]# usermod -G caiwu userC
[[email protected] ~]# id userC
uid=2000(userC) gid=2000(userC) groups=2000(userC),2008(caiwu)
[[email protected] ~]# usermod -aG caiwu userC //-a The parameter is to keep the current group of the user , Add a new group
[[email protected] ~]# id userC
uid=2000(userC) gid=2000(userC) groups=2000(userC),2008(caiwu),2009(jishu)
-L Lock user password
-U Unlock user password
6、 Delete user
userdel [ Options ] user name
-r Delete user's home directory
[[email protected] ~]# userdel -r userA
7、 View user login information
[[email protected] ~]# who
root pts/0 2020-12-17 17:09 (192.168.183.1)
root pts/1 2020-12-17 18:00 (192.168.183.1)
user01 :2 2020-12-17 19:35 (:2)
8、 View failed logins
[[email protected] ~]# lastb
9、 View all login behaviors
[[email protected] ~]# last
3、 ... and 、 User group management operations
User group related files :
/etc/group
1、 Create user group
groupadd Group name
2、 Delete user group
groupdel Group name
3、 Remove user from group
gpasswd [ Options ] user Group name
[[email protected] ~]# gpasswd -d apache tomcat
Removing user user01 from group tomcat
Four 、 User related profiles
Every time a user is created , The system will automatically /etc/skel Copy the files of the directory to the user's home directory
[[email protected] ~]# ls -a /home/user06/
. .. .bash_logout .bash_profile .bashrc
1、 .bash_profile Define environment variables
The commands in this file , It will be automatically executed when the user logs in to the system
[[email protected] ~]# vim /home/user01/.bash_profile
echo ' Automatic execution !'
[[email protected] ~]# su - user01
Last login: Thu Dec 17 23:02:59 CST 2020 on pts/6
Automatic execution !
[[email protected] ~]$ exit
Global file /etc/profile
Effective for all users in the system
2、 .bashrc Define command aliases
The command of this file , It will be automatically executed when the user opens a new terminal
Global file /etc/bashrc
// See aliases
[[email protected] ~]# alias
To delete an alias
[[email protected] ~]# unalias cs
For the user user01 Define command aliases
[[email protected] ~]# vim /home/user01/.bashrc
alias lc='ls -ldh /etc/'
[[email protected] ~]# su - user01
Last login: Thu Dec 17 23:07:23 CST 2020 on pts/5
Automatic execution !
[[email protected] ~]$ lc
drwxr-xr-x. 142 root root 8.0K Dec 17 23:15 /etc/
3、 .bash_history
After the user logs in to the system , Will appear , Record the historical commands executed by the corresponding user
history // View history command
history -c // Clear history command
Four 、 Reset root password
1、 Restart the system
2、 Boot to grub Menu interface , Press up and down , Pause start
3、 choice gruab The first item in the menu , By letter e Edit the system startup configuration file
4、 find linux16 Beginning line , Add... At the end of the line rd.break
5、 Press ctrl + x Start again , Enter rescue mode
6、 Remount the root directory by reading and writing
switch_root# mount -o rw,remount /sysroot
7、 Switch to the rescue mode root directory
switch_root# chroot /sysroot
8、 Use passwd Command reset password
sh-4.2# passwd root
9、 Create hidden files
sh-4.2# touch /.autorelabel
10、 Knock twice exit Exit rescue mode , The system will start normally
边栏推荐
- 读《机器学习-周志华》内容摘要
- 判断Set中课程是否存在,Contains方法
- 关于如何在终端设置有颜色的字体
- shell基本命令
- The use of file class, common APIs and how to traverse directories and subdirectories
- 查看进程!!!rpm安装!!!
- zstuAcm登记成绩(用STL链表list完成)
- Basic process of unit approval
- Day04 --- use of Zen
- About the problem of re creation after deleting the module in idea:
猜你喜欢
随机推荐
03. Design of large-scale high parallel micro service system
使用pip使用报错:pip is configured with locations that require TLS/SSL
关系型数据库10 分钟了解 MySQL
October essay
BeanShell 内置变量 ctx
Day04 --- use of Zen
zstuAcm夏令营旗手
UNIX实现IO多路复用之使用poll函数实现网络socket服务端
Learn the input file parameters of amber software MD
Garbled JS file
File类的使用,常用API及如何遍历目录及子目录
Learn the MD of amber t3.3: implicit solvent model (GB)
性能测试流程
Fundamentals of software testing
BeanShell内置变量vars的使用技巧
讀《高效閱讀法-最劃算的自我投資》有感
Shell编程规范与变量
Selenium基础知识 控制浏览器的滚动条
Day03 --- flow chart operation -- scenario method
Amber tutorial 4.6: hydrogen bond analysis of the system









