2、linux命令-用户管理 linux用户管理的含义
liebian365 2024-10-25 15:38 29 浏览 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 #取消禁?所有普通?户登录
相关推荐
- go语言也可以做gui,go-fltk让你做出c++级别的桌面应用
-
大家都知道go语言生态并没有什么好的gui开发框架,“能用”的一个手就能数的清,好用的就更是少之又少。今天为大家推荐一个go的gui库go-fltk。它是通过cgo调用了c++的fltk库,性能非常高...
- 旧电脑的首选系统:TinyCore!体积小+精简+速度极快,你敢安装吗
-
这几天老毛桃整理了几个微型Linux发行版,准备分享给大家。要知道可供我们日常使用的Linux发行版有很多,但其中的一些发行版经常会被大家忽视。其实这些微型Linux发行版是一种非常强大的创新:在一台...
- codeblocks和VS2019下的fltk使用中文
-
在fltk中用中文有点问题。英文是这样。中文就成这个样子了。我查了查资料,说用UTF-8编码就行了。edit->Fileencoding->UTF-8然后保存文件。看下下边的编码指示确...
- FLTK(Fast Light Toolkit)一个轻量级的跨平台Python GUI库
-
FLTK(FastLightToolkit)是一个轻量级的跨平台GUI库,特别适用于开发需要快速、高效且简单界面的应用程序。本文将介绍Python中的FLTK库,包括其特性、应用场景以及如何通过代...
- 中科院开源 RISC-V 处理器“香山”流片,已成功运行 Linux
-
IT之家1月29日消息,去年6月份,中科院大学教授、中科院计算所研究员包云岗,发布了开源高性能RISC-V处理器核心——香山。近日,包云岗在社交平台晒出图片,香山芯片已流片,回片后...
- Linux 5.13内核有望合并对苹果M1处理器支持的初步代码
-
预计Linux5.13将初步支持苹果SiliconM1处理器,不过完整的支持工作可能还需要几年时间才能完全完成。虽然Linux已经可以在苹果SiliconM1上运行,但这需要通过一系列的补丁才能...
- Ubuntu系统下COM口测试教程(ubuntu port)
-
1、在待测试的板上下载minicom,下载minicom有两种方法:方法一:在Ubuntu软件中心里面搜索下载方法二:按“Ctrl+Alt+T”打开终端,打开终端后输入“sudosu”回车;在下...
- 湖北嵌入式软件工程师培训怎么选,让自己脱颖而出
-
很多年轻人毕业即失业、面试总是不如意、薪酬不满意、在家躺平。“就业难”该如何应对,参加培训是否能改变自己的职业走向,在湖北,有哪些嵌入式软件工程师培训怎么选值得推荐?粤嵌科技在嵌入式培训领域有十几年经...
- 新阁上位机开发---10年工程师的Modbus总结
-
前言我算了一下,今年是我跟Modbus相识的第10年,从最开始的简单应用到协议了解,从协议开发到协议讲解,这个陪伴了10年的协议,它一直没变,变的只是我对它的理解和认识。我一直认为Modbus协议的存...
- 创建你的第一个可运行的嵌入式Linux系统-5
-
@ZHangZMo在MicrochipBuildroot中配置QT5选择Graphic配置文件增加QT5的配置修改根文件系统支持QT5修改output/target/etc/profile配置文件...
- 如何在Linux下给zigbee CC2530实现上位机
-
0、前言网友提问如下:粉丝提问项目框架汇总下这个网友的问题,其实就是实现一个网关程序,内容分为几块:下位机,通过串口与上位机相连;下位机要能够接收上位机下发的命令,并解析这些命令;下位机能够根据这些命...
- Python实现串口助手 - 03串口功能实现
-
串口调试助手是最核心的当然是串口数据收发与显示的功能,pzh-py-com借助的是pySerial库实现串口收发功能,今天痞子衡为大家介绍pySerial是如何在pzh-py-com发挥功能的。一、...
- 为什么选择UART(串口)作为调试接口,而不是I2C、SPI等其他接口
-
UART(通用异步收发传输器)通常被选作调试接口有以下几个原因:简单性:协议简单:UART的协议非常简单,只需设置波特率、数据位、停止位和校验位就可以进行通信。相比之下,I2C和SPI需要处理更多的通...
- 同一个类,不同代码,Qt 串口类QSerialPort 与各种外设通讯处理
-
串口通讯在各种外设通讯中是常见接口,因为各种嵌入式CPU中串口标配,工业控制中如果不够还通过各种串口芯片进行扩展。比如spi接口的W25Q128FV.对于软件而言,因为驱动接口固定,软件也相对好写,因...
- 嵌入式linux为什么可以通过PC上的串口去执行命令?
-
1、uboot(负责初始化基本硬bai件,如串口,网卡,usb口等,然du后引导系统zhi运行)2、linux系统(真正的操作系统)3、你的应用程序(基于操作系统的软件应用)当你开发板上电时,u...
你 发表评论:
欢迎- 一周热门
- 最近发表
-
- go语言也可以做gui,go-fltk让你做出c++级别的桌面应用
- 旧电脑的首选系统:TinyCore!体积小+精简+速度极快,你敢安装吗
- codeblocks和VS2019下的fltk使用中文
- FLTK(Fast Light Toolkit)一个轻量级的跨平台Python GUI库
- 中科院开源 RISC-V 处理器“香山”流片,已成功运行 Linux
- Linux 5.13内核有望合并对苹果M1处理器支持的初步代码
- Ubuntu系统下COM口测试教程(ubuntu port)
- 湖北嵌入式软件工程师培训怎么选,让自己脱颖而出
- 新阁上位机开发---10年工程师的Modbus总结
- 创建你的第一个可运行的嵌入式Linux系统-5
- 标签列表
-
- 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)