2、linux命令-用户管理 linux用户管理的含义
liebian365 2024-10-25 15:38 22 浏览 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 #取消禁?所有普通?户登录
相关推荐
- 4万多吨豪华游轮遇险 竟是因为这个原因……
-
(观察者网讯)4.7万吨豪华游轮搁浅,竟是因为油量太低?据观察者网此前报道,挪威游轮“维京天空”号上周六(23日)在挪威近海发生引擎故障搁浅。船上载有1300多人,其中28人受伤住院。经过数天的调...
- “菜鸟黑客”必用兵器之“渗透测试篇二”
-
"菜鸟黑客"必用兵器之"渗透测试篇二"上篇文章主要针对伙伴们对"渗透测试"应该如何学习?"渗透测试"的基本流程?本篇文章继续上次的分享,接着介绍一下黑客们常用的渗透测试工具有哪些?以及用实验环境让大家...
- 科幻春晚丨《震动羽翼说“Hello”》两万年星间飞行,探测器对地球的最终告白
-
作者|藤井太洋译者|祝力新【编者按】2021年科幻春晚的最后一篇小说,来自大家喜爱的日本科幻作家藤井太洋。小说将视角放在一颗太空探测器上,延续了他一贯的浪漫风格。...
- 麦子陪你做作业(二):KEGG通路数据库的正确打开姿势
-
作者:麦子KEGG是通路数据库中最庞大的,涵盖基因组网络信息,主要注释基因的功能和调控关系。当我们选到了合适的候选分子,单变量研究也已做完,接着研究机制的时便可使用到它。你需要了解你的分子目前已有哪些...
- 知存科技王绍迪:突破存储墙瓶颈,详解存算一体架构优势
-
智东西(公众号:zhidxcom)编辑|韦世玮智东西6月5日消息,近日,在落幕不久的GTIC2021嵌入式AI创新峰会上,知存科技CEO王绍迪博士以《存算一体AI芯片:AIoT设备的算力新选择》...
- 每日新闻播报(September 14)_每日新闻播报英文
-
AnOscarstatuestandscoveredwithplasticduringpreparationsleadinguptothe87thAcademyAward...
- 香港新巴城巴开放实时到站数据 供科技界研发使用
-
中新网3月22日电据香港《明报》报道,香港特区政府致力推动智慧城市,鼓励公私营机构开放数据,以便科技界研发使用。香港运输署21日与新巴及城巴(两巴)公司签署谅解备忘录,两巴将于2019年第3季度,开...
- 5款不容错过的APP: Red Bull Alert,Flipagram,WifiMapper
-
本周有不少非常出色的app推出,鸵鸟电台做了一个小合集。亮相本周榜单的有WifiMapper's安卓版的app,其中包含了RedBull的一款新型闹钟,还有一款可爱的怪物主题益智游戏。一起来看看我...
- Qt动画效果展示_qt显示图片
-
今天在这篇博文中,主要实践Qt动画,做一个实例来讲解Qt动画使用,其界面如下图所示(由于没有录制为gif动画图片,所以请各位下载查看效果):该程序使用应用程序单窗口,主窗口继承于QMainWindow...
- 如何从0到1设计实现一门自己的脚本语言
-
作者:dong...
- 三年级语文上册 仿写句子 需要的直接下载打印吧
-
描写秋天的好句好段1.秋天来了,山野变成了美丽的图画。苹果露出红红的脸庞,梨树挂起金黄的灯笼,高粱举起了燃烧的火把。大雁在天空一会儿写“人”字,一会儿写“一”字。2.花园里,菊花争奇斗艳,红的似火,粉...
- C++|那些一看就很简洁、优雅、经典的小代码段
-
目录0等概率随机洗牌:1大小写转换2字符串复制...
- 二年级上册语文必考句子仿写,家长打印,孩子照着练
-
二年级上册语文必考句子仿写,家长打印,孩子照着练。具体如下:...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- wireshark怎么抓包 (75)
- qt sleep (64)
- cs1.6指令代码大全 (55)
- factory-method (60)
- sqlite3_bind_blob (52)
- hibernate update (63)
- c++ base64 (70)
- nc 命令 (52)
- wm_close (51)
- epollin (51)
- sqlca.sqlcode (57)
- lua ipairs (60)
- tv_usec (64)
- 命令行进入文件夹 (53)
- postgresql array (57)
- statfs函数 (57)
- .project文件 (54)
- lua require (56)
- for_each (67)
- c#工厂模式 (57)
- wxsqlite3 (66)
- dmesg -c (58)
- fopen参数 (53)
- tar -zxvf -c (55)
- 速递查询 (52)