linux 用户管理

# groupadd -r nfsgrp

加入组id号,低于499的系统账号

# useradd -G nfsgrp -md /var/nfs -s /sbin/nologin nfs1

-m 自动建立用户登入目录

-d 指定用户登入的起始目录

-s 指定用户登入后所使用的shell

# useradd -n user4

取消建立以用户名称为名的群组

# useradd -D -s /bin/vi

-D 变更预设值

# usermod -L user2

# tail /etc/shadow

用user2登陆一下试一试

# usermod -U user2

usermod -aG root user6

将用户user6加入附加组root

------------------------------------------------

# userdel user6

# ls -ld /home/user6

并没有删除家目录

# userdel -r user3

# ls -ld /home/user3

-r删除用户的同时删除家目录

groupadd -g 888 group2

-g指定组id号

group -n newgroup mygroup

-n重命名组名

---------------------------------------------------

# useradd myuser

# groupdel myuser

主组不能删除

userdel myuser

这样自然删除了

useradd -a tom student

将用户tom加到组student里面

id alice

查询用户alice

groups alice

查询用户alice所属的组


newgrp student

以相同的用户 不同的组名称登入系统 

创建文件时的组会发生改变

gpasswd -d alice student

将用户alice 从student给中删除

groupdel student

直接创建的组可以删除

passwd -l jerry

锁用户jerry 

passwd -S jerry

jerry PS 2018-11-30 0 99999 7 -1

-S     Report  password  status  on  the  named account. The first part

indicates if the user account is locked (LK),  hasno password

(NP),  or  has  an  existing or locked password (PS). The second

              part gives the date of the last password change. The next  parts

              are the minimum age, maximum age, warning period, and inactivity

              period for the password.

# passwd -n1 -x60 -w7 -i0 jerry

passwd -n This will set the minimum password lifetime

-x 设置密码的有效期

-w用户密码过期提前几天收到

-i过期后停止用户账号

date -s "2020-10-10"

修改系统时间

chage -l jerry

显示用户密码信息

chage -d 0 jerry

密码最后一次的修改日期

chage -d 5 student修改时间就变成1970年1月6日。也可以直接接日期如chage -d 2013-02-18 student密码修改时间就变成了2013年2月18日。如果

用命令chage -d 0 student则代表该用户需立即修改密码。

普通用户登陆

$ cat /etc/shadow

普通用户无权限查看

$ sudo passwd root

普通用户没有sudo权限

visudo 

编辑/etc/sudoers

jerry ALL=(root) !/usr/bin/passwd root, !/usr/bin/passwd, /usr/bin/passwd [a-zA-Z]*

当用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo的权限

Linux w命令用于显示目前登入系统的用户信息。

Linux who命令用于显示系统中有哪些使用者正在上面

 whoami     显示当前用户名称

sugid 

只有可以执行的二进制程序 才能设定sugid权限

任何普通用户执行sugid文件,临时有执行权限,变为文件所有者

chown u+s 文件名

r w x 4 2 1 

s s t  4 2 1 

sgid 

临时有组所有者

# cd /tmp

# mkdir acl

# ll -d acl

# echo "hello myacl" > acl/hello.txt

# ll acl/hello.acl

# setfacl -m u:tom:--- acl/hello.txt

# getfacl acl

# getfacl acl/hello.txt

# su - tom

$ cat /tmp/acl/hello.txt ;被拒绝

$ mkdir /tmp/acl/tomdir            ;被拒绝

$ exit

getfacl 查看文件的acl权限

对tom无任何权限

 -m表示设置文件acl规则

# setfacl -m d:u:jerry:--- acl

d:默认设定默认的acl规则,针对目录而言.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容