2、linux命令-用户管理(linux用户管理总结)
nanshan 2024-11-04 13:06 9 浏览 0 评论
linux命令-用户管理
用户切换
[root@eric ~]# su eric # 切换到用户eric
[eric@eric root]$
[eric@eric root]$ su # 切换到root
Password:
[root@eric ~]#
[root@eric ~]# exit # 退出当前用户
exit
[eric@eric root]$
usermod ye02 -G wheel # 用户组切换
用户信息存储位置
# /etc/passwd # 存储Linux中的?户信息
# /etc/shadow # 存储Linux中的?户密码信息
# /etc/group # 存储Linux中的?户组信息
# /etc/gshadow # 存储Linux中的?户组密码信息
passwd文件解读
useradd zhangsan
more /etc/passwd
zhangsan:x:1002:1002::/home/zhangsan:/bin/bash
[1]:[2]:[3]:[4]:[5]:[6]:[7]
[1] : ?户名
[2] : ?户密码 | X - 密码单独存储在/etc/shadow
[3] : ?户ID
[4] : 组ID group-id (GID) # 主组
[5] : ?户描述信息
[6] : 该?户的家?录
[7] : ?户所使?的默认shell壳-类型
shell类型
#查看当前系统中?持的linux shell类型
[root@centos7 ~]# cat /etc/shells
/bin/sh #最古?
/bin/bash #最常?/最常?
/sbin/nologin # ?户禁?登录
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
#查看当前环境正在使?shell
[root@centos7 ~]# echo $SHELL
/bin/bash
#临时shell切换
[root@centos7 ~]# sh
sh-4.2#
sh-4.2# bash
#永久切换(账户退出重新登录后?效)
[root@centos7 tom]# chsh -s /bin/sh
Changing shell for root.
Shell changed.
用户操作
没有指定uid和gid,系统默认从1001开始,自动创建命令home/用户,自动使用bash
useradd zhangsan
useradd -u 2001 lisi # 指定uid
useradd -u 2002 -c "description" user02 #添加描述
useradd -u 2003 -s /bin/csh user03 #指定shell
useradd user04 -u 2004 -d /home/user04 # 指定家目录
useradd user05 -u 2005 -g 2004 # 指定用户组(用户组必须已经存在)
useradd user07 -u 2007 -g 2004 -G 2003 # 指定扩展用户组(扩展用户组必须已经存在)
[root@eric home]# cat /etc/passwd
user07:x:2007:2004::/home/user07:/bin/bash
[root@eric home]# cat /etc/group
user03:x:2003:user07
[root@eric home]# id user07
uid=2007(user07) gid=2004(user04) groups=2004(user04),2003(user03)
[user07@eric home]$ cd user07 #切换到用户07
[user07@eric ~]$ touch 128.txt
-rw-r--r--. 1 user07 user04 0 Jul 31 18:46 128.txt 默认创建文件在user04组
[user07@eric ~]$ newgrp user03 #切户用户组到03。(可以采用命令exit退出该用户组03)
[user07@eric ~]$ touch 456.txt
-rw-r--r--. 1 user07 user03 0 Jul 31 18:50 456.txt 创建文件的所属组在03
userdel user08 #删除用户,用户组没有其他成员的话,也会相应删除用户组。
userdel -r user05 # 删除用户及对应的信息
userdel -rf user05 # 强制删除用户及对应的信息
/etc/shadow文件解读
user01:$6$bfcEHLZS$rfpTnTE8vogY0cWFRJqks9qdwsB0vukkCiWL7Hj/Xwe0p0LjkpEYUIDGA1XW
QcwxA8BsLd5P2m2lG3L/avZJd/:20615:0:99999:7:::
user02:!!:20615:0:99999:7:::
[1]:[2]:[3]:[4]:[5]:[6]:[7]:[8]:[9]
[1] : ?户名
[2] : 密码 | “!!” 账号锁定 / $6$ 密码已经设置,并且密码本地加密。
/etc/logins.defs
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512 (哈希法)
[3] : 上次修改密码时间 (从1970-1-1 (unix)到 修改密码当天)
[4] : 密码的最短有效期 (3) | 0 【不设置最短有效期】
[5] : 密码的最?有效期 (30)| 99999
[6] : 密码到期前多久发送告警 - 7 提前7天发送警告
[7] : 密码过期后的宽限?期 - 8 再宽限8天
[8] : 账号的失效?期 ------优先级最?, ?旦当前参数到期,该账号直接?即?法使?。 (从
1970-1-1 (unix)到 修改密码当天)
[9] : 保留
用户密码管理
[root@eric ~]# passwd --help
Usage: passwd [OPTION...]
-k, --keep-tokens keep non-expired authentication tokens
-d, --delete delete the password for the named account (root only)
-l, --lock lock the password for the named account (root only)
-u, --unlock unlock the password for the named account (root only)
-e, --expire expire the password for the named account (root only)
-f, --force force operation
-x, --maximum=DAYS maximum password lifetime (root only)
-n, --minimum=DAYS minimum password lifetime (root only)
-w, --warning=DAYS number of days warning users receives before password
expiration (root only)
-i, --inactive=DAYS number of days after password expiration when an account
becomes disabled (root only)
-S, --status report password status on the named account (root only)
--stdin read new tokens from stdin (root only)
Help options:
-?, --help Show this help message
--usage Display brief usage message
root账号可直接修改密码。用户修改自己的账号需要提交旧密码,并有大小写等要求。
root@eric user07]# passwd user01
[root@eric ~]# passwd -S user01 # 查看用户密码情况
user01 PS 2023-07-31 0 99999 7 -1 (Password set, SHA512 crypt.)
[root@eric ~]# passwd -l user02 # 锁定用户user02
Locking password for user user02.
passwd: Success
[root@eric ~]# passwd -u user02 # 解除锁定用户user02
chage -E 2023-8-1 user01 #强制用户的实效时间。
chage -d 0 user01 # 下次登录时候强制修改密码
passwd -e user01 # 下次登录时候强制修改密码
passwd -d user02 # 删除用户密码
echo "123" | passwd --stdin user01 通过管道方式修改密码
passwd -n 3 -x 30 -w 5 -i 2 user01 #最短3天最长30天提前5天警告宽限2天
用户组管理
#?户组信息
cat /etc/group
user02:x:2002:user01
[1]:[2]:[3]:[4]
[1]: ?户组组名
[2]: ?户组密码信息
[3]: ?户组ID
[4]: 附加?户组成员
groupadd wangwu # 新增用户组
[root@eric ~]# cat /etc/group
wangwu:x:2009:
groupdel wangwu2 # 删除用户组
groupadd -g 3001 wangwu2 # 指定id创建组
usermod命令
[root@eric ~]# usermod --help
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user SEUSER new SELinux user mapping for the user account
usermod user01 -g 2003 # 已经创建的用户需要通过usermod修改组,-g修改默认值
usermod user01 -G 2004 # -G 覆盖模式,增加或者修改扩展组
usermod user01 -aG 2002 # -aG 追加模式,增加扩展组
gpasswd命令
[root@eric ~]# gpasswd --help
Usage: gpasswd [option] GROUP
Options:
-a, --add USER add USER to GROUP
-d, --delete USER remove USER from GROUP
-h, --help display this help message and exit
-Q, --root CHROOT_DIR directory to chroot into
-r, --delete-password remove the GROUP's password
-R, --restrict restrict access to GROUP to its members
-M, --members USER,... set the list of members of GROUP
-A, --administrators ADMIN,...
set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.
gpasswd wangwu # 用户组密码设置,用于用户切换用户组时候输入密码
[root@eric ~]# gpasswd -d user04 user02 # user02组中删除user04用户
Removing user user04 from group user02
[root@eric ~]# gpasswd -a user04 user02 # user02用户组添加user04用户
Adding user user04 to group user02
/var/spool/mail 删除用户后,该目录下用户文件夹需要手工删除
[root@eric ~]# ls /var/spool/mail
eric ovswitch rpc user02 user04 user10
lisi root user01 user03 user07 zhangsan
[root@eric ~]# rm -rf /var/spool/mail/uer03 # user03用户删除后,该目录还在,需要手工删除。
[root@eric mail]# ls -a /home/user02 #创建用户时候,系统会自动生成隐藏文件。(不建议手动创建家目录文件夹)
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@eric skel]# ls /etc/skel -a # 在该文件夹下创建文件,之后添加用户时候会自动添加到用户的家目录。
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@eric ~]# chfn # 修改用户描述信息
Changing finger information for root.
Name [root]: user10
Office []: abc
Office Phone []: 123
Home Phone []: 123
Finger information changed.
向用户弹窗
[root@eric ~]# wall "this sever will be shutdown,please exit" # 向所有用户弹窗
Broadcast message from root@eric.centos7 (pts/0) (Tue Aug 1 17:46:49 2023):
this sever will be shutdown,please exit
禁止用户登录
[root@centos7 ~]# touch /etc/nologin #禁?所有普通?户登录
[root@centos7 ~]# rm -rf touch /etc/nologin #取消禁?所有普通?户登录
相关推荐
- 实战派 | Java项目中玩转Redis6.0客户端缓存
-
铺垫首先介绍一下今天要使用到的工具Lettuce,它是一个可伸缩线程安全的redis客户端。多个线程可以共享同一个RedisConnection,利用nio框架Netty来高效地管理多个连接。放眼望向...
- 轻松掌握redis缓存穿透、击穿、雪崩问题解决方案(20230529版)
-
1、缓存穿透所谓缓存穿透就是非法传输了一个在数据库中不存在的条件,导致查询redis和数据库中都没有,并且有大量的请求进来,就会导致对数据库产生压力,解决这一问题的方法如下:1、使用空缓存解决对查询到...
- Redis与本地缓存联手:多级缓存架构的奥秘
-
多级缓存(如Redis+本地缓存)是一种在系统架构中广泛应用的提高系统性能和响应速度的技术手段,它综合利用了不同类型缓存的优势,以下为你详细介绍:基本概念本地缓存:指的是在应用程序所在的服务器内...
- 腾讯云国际站:腾讯云服务器如何配置Redis缓存?
-
本文由【云老大】TG@yunlaoda360撰写一、安装Redis使用包管理器安装(推荐)在CentOS系统中,可以通过yum包管理器安装Redis:sudoyumupdate-...
- Spring Boot3 整合 Redis 实现数据缓存,你做对了吗?
-
你是否在开发互联网大厂后端项目时,遇到过系统响应速度慢的问题?当高并发请求涌入,数据库压力剧增,响应时间拉长,用户体验直线下降。相信不少后端开发同行都被这个问题困扰过。其实,通过在SpringBo...
- 【Redis】Redis应用问题-缓存穿透缓存击穿、缓存雪崩及解决方案
-
在我们使用redis时,也会存在一些问题,导致请求直接打到数据库上,导致数据库挂掉。下面我们来说说这些问题及解决方案。1、缓存穿透1.1场景一个请求进来后,先去redis进行查找,redis存在,则...
- Spring boot 整合Redis缓存你了解多少
-
在前一篇里面讲到了Redis缓存击穿、缓存穿透、缓存雪崩这三者区别,接下来我们讲解Springboot整合Redis中的一些知识点:之前遇到过,有的了四五年,甚至更长时间的后端Java开发,并且...
- 揭秘!Redis 缓存与数据库一致性问题的终极解决方案
-
在现代软件开发中,Redis作为一款高性能的缓存数据库,被广泛应用于提升系统的响应速度和吞吐量。然而,缓存与数据库之间的数据一致性问题,一直是开发者们面临的一大挑战。本文将深入探讨Redis缓存...
- 高并发下Spring Cache缓存穿透?我用Caffeine+Redis破局
-
一、什么是缓存穿透?缓存穿透是指查询一个根本不存在的数据,导致请求直接穿透缓存层到达数据库,可能压垮数据库的现象。在高并发场景下,这尤其危险。典型场景:恶意攻击:故意查询不存在的ID(如负数或超大数值...
- Redis缓存三剑客:穿透、雪崩、击穿—手把手教你解决
-
缓存穿透菜小弟:我先问问什么是缓存穿透?我听说是缓存查不到,直接去查数据库了。表哥:没错。缓存穿透是指查询一个缓存中不存在且数据库中也不存在的数据,导致每次请求都直接访问数据库的行为。这种行为会让缓存...
- Redis中缓存穿透问题与解决方法
-
缓存穿透问题概述在Redis作为缓存使用时,缓存穿透是常见问题。正常查询流程是先从Redis缓存获取数据,若有则直接使用;若没有则去数据库查询,查到后存入缓存。但当请求的数据在缓存和数据库中都...
- Redis客户端缓存的几种实现方式
-
前言:Redis作为当今最流行的内存数据库和缓存系统,被广泛应用于各类应用场景。然而,即使Redis本身性能卓越,在高并发场景下,应用于Redis服务器之间的网络通信仍可能成为性能瓶颈。所以客户端缓存...
- Nginx合集-常用功能指导
-
1)启动、重启以及停止nginx进入sbin目录之后,输入以下命令#启动nginx./nginx#指定配置文件启动nginx./nginx-c/usr/local/nginx/conf/n...
- 腾讯云国际站:腾讯云怎么提升服务器速度?
-
本文由【云老大】TG@yunlaoda360撰写升级服务器规格选择更高性能的CPU、内存和带宽,以提供更好的处理能力和网络性能。优化网络配置调整网络接口卡(NIC)驱动,优化TCP/IP参数...
- 雷霆一击服务器管理员教程
-
本文转载莱卡云游戏服务器雷霆一击管理员教程(搜索莱卡云面版可搜到)首先你需要给服务器设置管理员密码,默认是空的管理员密码在启动页面进行设置设置完成后你需要重启服务器才可生效加入游戏后,点击键盘左上角E...
你 发表评论:
欢迎- 一周热门
-
-
爱折腾的特斯拉车主必看!手把手教你TESLAMATE的备份和恢复
-
如何在安装前及安装后修改黑群晖的Mac地址和Sn系列号
-
[常用工具] OpenCV_contrib库在windows下编译使用指南
-
WindowsServer2022|配置NTP服务器的命令
-
Ubuntu系统Daphne + Nginx + supervisor部署Django项目
-
WIN11 安装配置 linux 子系统 Ubuntu 图形界面 桌面系统
-
解决Linux终端中“-bash: nano: command not found”问题
-
Linux 中的文件描述符是什么?(linux 打开文件表 文件描述符)
-
K3s禁用Service Load Balancer,解决获取浏览器IP不正确问题
-
NBA 2K25虚拟内存不足/爆内存/内存占用100% 一文速解
-
- 最近发表
-
- 实战派 | Java项目中玩转Redis6.0客户端缓存
- 轻松掌握redis缓存穿透、击穿、雪崩问题解决方案(20230529版)
- Redis与本地缓存联手:多级缓存架构的奥秘
- 腾讯云国际站:腾讯云服务器如何配置Redis缓存?
- Spring Boot3 整合 Redis 实现数据缓存,你做对了吗?
- 【Redis】Redis应用问题-缓存穿透缓存击穿、缓存雪崩及解决方案
- Spring boot 整合Redis缓存你了解多少
- 揭秘!Redis 缓存与数据库一致性问题的终极解决方案
- 高并发下Spring Cache缓存穿透?我用Caffeine+Redis破局
- Redis缓存三剑客:穿透、雪崩、击穿—手把手教你解决
- 标签列表
-
- linux 查询端口号 (58)
- docker映射容器目录到宿主机 (66)
- 杀端口 (60)
- yum更换阿里源 (62)
- internet explorer 增强的安全配置已启用 (65)
- linux自动挂载 (56)
- 禁用selinux (55)
- sysv-rc-conf (69)
- ubuntu防火墙状态查看 (64)
- windows server 2022激活密钥 (56)
- 无法与服务器建立安全连接是什么意思 (74)
- 443/80端口被占用怎么解决 (56)
- ping无法访问目标主机怎么解决 (58)
- fdatasync (59)
- 405 not allowed (56)
- 免备案虚拟主机zxhost (55)
- linux根据pid查看进程 (60)
- dhcp工具 (62)
- mysql 1045 (57)
- 宝塔远程工具 (56)
- ssh服务器拒绝了密码 请再试一次 (56)
- ubuntu卸载docker (56)
- linux查看nginx状态 (63)
- tomcat 乱码 (76)
- 2008r2激活序列号 (65)