![cover](https://img-blog.csdnimg.cn/ce94141bec314a8fb477b20ec68d2efa.png)
Linux如何建立用户(组)及调整用户(组)属性(案列+详细指令)
目录一、建立组:二、建立用户:三、建立一个程序用户四、为用户设置及修改密码属性五、删除用户和组:用户组简介:(12条消息) Linux中用户、用户组(一):概念以及设置用户、用户组的意义_传奇冰行的博客-CSDN博客_linux中用户和组的概念一、建立组:需求:建立一个名为 class1 的组 ID 为 2021,class2 的组 ID 为 2022[root@localhost poem]#
·
目录
用户组简介:
(12条消息) Linux中用户、用户组(一):概念以及设置用户、用户组的意义_传奇冰行的博客-CSDN博客_linux中用户和组的概念
一、建立组:
需求:建立一个名为 class1 的组 ID 为 2021,class2 的组 ID 为 2022
[root@localhost poem]# groupadd -g 2021 class1 ——建立
[root@localhost poem]# groupadd -g 2022 class2 ——建立
[root@localhost poem]# groupmod -g 1021 class1 ——修改
[root@localhost poem]# groupmod -g 2021 class1 ——修改为2021
[root@localhost poem]# vim /etc/group ——查看
二、建立用户:
需求:建立 tom 用户要求其基本组是 class1,附加组为 class2,tom 用户的 UID 为 600
[root@localhost poem]# useradd -g class1 -G class2 -u 600 tom ——建立(也可以单独写)
[root@localhost poem]# id tom ——查看
uid=600(tom) gid=2021(class1) groups=2021(class1),2022(class2)
[root@localhost poem]#
[root@localhost poem]# usermod +修改内容 ——修改
三、建立一个程序用户
需求:建立一个程序用户 UID 为 250,用户名为 testuser,没有家目录(程序用户 没有登录系统权限)
[root@localhost poem]# useradd -u 250 -M -s /sbin/nologin testuser ——建立
[root@localhost poem]# id testuser ——查看
uid=250(testuser) gid=2023(testuser) groups=2023(testuser)
[root@localhost poem]# su - testuser ——登录测试
su: warning: cannot change directory to /home/testuser: No such file or directory
This account is currently not available.
[root@localhost poem]#
-M (没有家目录)-s /sbin/nologin testuser(不使用命令解释器)
四、为用户设置及修改密码属性
需求:为 tom 用户设定密码为 123,并设定密码最长有效期为 90 天,将用户密码 进行锁定使其无法登录
[root@localhost poem]# passwd tom 123 ——设置密码
[root@localhost tom]# chage -M 90 tom ——设置密码最长有效期
[root@localhost tom]# passwd -S tom ——查看
tom PS 2022-04-08 0 90 7 -1 (Password set, MD5 crypt.)
[root@localhost tom]# passwd -l tom ——锁定
Locking password for user tom.
passwd: Success
此时无法登录tom账户:
[root@localhost tom]# passwd -u tom ——解锁
Unlocking password for user tom.
passwd: Success
[root@localhost tom]#
[root@localhost tom]# passwd -S tom ——查看用户信息
tom PS 2022-04-08 0 90 7 -1 (Password set, MD5 crypt.)
[root@localhost tom]#
五、删除用户和组:
[root@localhost tom]# userdel -r tom
[root@localhost tom]# userdel -r testuser
[root@localhost tom]# groupdel class1 ——删除组
更多推荐
所有评论(0)