Day26Linux系统用户分类,建立及调整用户属性,调整文件以及目录权限

Linux系统用户分类:
su -xiyangyang
root切换到普通用户不需要输入密码
cat /etc/shadow
使用xiyangyxang用户访问/etc/shadow被拒绝
reboot
使用喜羊羊用户重启系统报错
exit
xiyangyang :普通用户,权限比管理员低,也可以登录系统
root :超级管理员
用户的分类和组:
/etc/passwd:保存了操作系统中所有用户的信息
vim /etc/passwd/
:set nu
root : x : 0 : 0 :root:/root:/bin/bash
xiyangyang: x : 500 : 500 : :/home/xiyangyang:/bin/bash
字段1:用户名称
字段2:密码占位符
字段3:用户的uid(0表示超级用户,500-6000普通用户,1-499程序用户,不允许登录系统,程序用户字段7:/sbin/nologin)
字段4:基本组的gid(先有组,再有用户)
字段5:用户信息记录字段
字段6:用户家目录
字段7:用户登录系统后使用的命令解释器
vim /etc/sahdow
:set nu

/etc/shadow:保存了用户的密码信息
root : 6 6 6… : 18085 : 0 : 99999 : 7 : : :
字段1:用户名
字段2:用户的密码加密后的字符串
字段3:距离1970/1/1密码最近一次的修改时间
字段4:密码最短有效期(3,3天内不可修改;0,不限制)
字段5:密码的最长有效期(建议90)
字段6:密码过期前7天警告
字段7:密码的不活跃期
字段8:用户的失效日期

/etc/group:记录了系统中所有组的信息
vim /etc/group

建立以及调整用户属性:
在这里插入图片描述1.groupadd class1
cat etc/group
组id未501,题目要求1000
groupmod -g 1000 class1
cat etc/group
groupadd -g 2000 class2
cat etc/group
2.useradd -g class1 tom
-g:基本组
id tom
user+tab可以查看以user开头的指令
usermod -G 2000 -u 600 tom
-G附加组
-u uid
id tom
su -tom
exit
3.useradd -u 250 -M -s /sbin/nologin testuser
id testuser
su -tsetuser
cd /home/
ls
无家目录
-M无家目录
-s /sbin/nologin不允许登录系统
4.passwd tom
新密码:123(太短,建议采用四分之三原则)
确认密码:123(由于是root登录,还是可以)
cat /etc/shadow
man chage
chage -M 90 tom
id tom
passwd -S tom
cat /etc/shadow
System------log out root
tom-----------123登录
终端----------root登录
锁定tom:
passwd -l tom
passwd -s tom
vim /etc/shadow
tom:!!$6…
!!表示密码被锁
-s:查看密码状态
-l:锁定用户
-u:解锁
passwd -u tom
passwd -s tom

5.userdel -r testuser
-r:连通家目录一起删除
userdel -r tom
id tom
groupdel class1
groupdel class2

调整文件以及目录权限:
权限:文件或者目录属于谁,属于哪个组,不同的用户能对该文件进行何种操作
vim /tmp/test.txt
{hello
nihao
hello
}
:wq
mkdir /tmp/testdir
cd /tmp
ls -l test.txt //查看文件权限
ls -ld testdir //查看目录权限
– rw- r-- r-- . 1 root root 18 jul 10 18:24 test.txt
d rwx r-x r-x. 2 root root 4096 jul 10 18:24 testdir/
1:节点 2:目录中的子目录个数
root:第一个代表用户名(所属者),第二个代表组名(所属组)
18,4096:文件大小
test.txt:文件
testdir/:目录
– rw- r-- r-- .
d rwx r-x r-x .
tom附加组基本组是root组
字段1:文件类型
-普通文件
d目录
l符号链接
b块设备
字段2:文件所属者对该文件的权限
r w x
文件 read读取文件 write写入文件 可执行权限
目录 可以查看目录内容 可以添加或删除文件 可以进入目录
字段3:文件所属组的权限
useradd tom
id tom
字段4:其他用户的权限(既不是文件的所有者,也不是文件所属组中的用户)
su - tom
cat /tmp/test.txt
echo “xxxx” > /tmp/test.txt
报错:权限被拒绝
exit
chmod 对象 算数运算符 权限 文件
用户:u g o a
u:所属者
g:所属组
o:其他用户权限
a:all
chmod o-r /tmp/test.txt
ll /tmp/test.txt
算数运算符:- + =
权限:r w x
改变文件的所属者为tom,所属组为tom组
chown tom /tmp/test.txt
chgrp tom /tmp/test.txt
su - tom
exh “xxx” > /tmp/test.txt
cat /tmp/test.txt
chown 用户文件
chgrp 组文件
chmod u+w 文件
cd /tmp/
ll test.txt
出现:rwxrw-r–
chmod 764 test.txt
ll test.txt
chmod 664 test.txt
0 000 —
1 001 --x
2 010 -w-
3 011 -wx
4 100 r–
5 101 r-x
6 110 rw-
7 111 rwx
rwx r-- —
7 4 0
粘滞位,sgid,suid权限
粘滞位:针对目录进行赋权,目录中创建文件只有创建者可删除
useradd tom
useradd jerry
mkdir test
chmod 777 test
ll -d test
su tom
touch tom.txt
ll
exit
su jerry
cd test
touch jerry.txt
rm -fr jerry.txt
rm -fr tom.txt
ls
ll -d 可以删除
jerry:drwxrwxrwx有权限
exit
chmod o+t test
su tom
cd test
ls
touch tom.txt
exit
su jerry
cd test
ls
rm -fr tom.txt报错
touch jerry.txt
ls
rm -fr jerry.txt
exit
cd …
ll
tmp:目录具有粘滞位
sgid:针对目录建立的权限,在该目录中建立的文件所属组,继承父目录的所属组
cd /tmp/
ll
chmod g+s test
ll -d test
drwxrwsrwt.
cd test
ls
rm -fr tom
ls
rm -fr tom.txt
touch tom
ll
(tom root)
suid:对可执行问价建立,
谁运行该文件谁就具有该文件所属者的权限
su tom
cd
cat /etc/passwd
cat /etc/shadow
ll /etc/passwd
ll /etc/shadow
vim /etc/passwd
改一个?:wq,无法保存,:q!退出
vim /etc/shadow
Permission Denied权限被拒绝
:q!
root:vim /etc/shadow可以看见
which vim
ll /usr/bin/vim
chmod u+s /usr/bin/vim
红底白字
su tom
vim /etc/shadow
删除喜羊羊账号密码
:wq!
ll /etc/shadow
tom:su - jerry要密码
su -xiyangyang不要密码,因为密码已经被删除了
chmod o-t,g-s,u-s
ll -d test
chmod g-s,o-t test
echo $PATH 看path变量保存了哪些信息
find /usr/bin -per 4757
4:代表suid
su tom
passwd改密码旧的新的确认
ll /etc/shadow
chmod u-s /usr/bin/vim
1.不再允许添加新用户的请求
/etc/group
/etc/passwd
/etc/shadow
/home/xxxx
chattr +i
chattr -i
man chattr 查看chattr用法
chattr可以更改文件属性,immutable不可更改
chattr +i /etc/passwd /etc/shadow锁定
lsattr /etc/passwd /etc/shadow
useradd testuser报错:不能打开/etc/passwd
chattr -i /etc/passwd /etc/shadow 解锁
2.rwxr-xr-x
7 5 5
cd /tmp/test
ls
tom
rm -rf from
ll
touch root.txt
mkdir rootdir
ll
su tom
touch tom.txt
mkdir tomdir
ll
tom:usmask:0002
root:usmask:0022
目录的最高权限0777-0022=0775
文件的最高权限0666-0022=0644
根据umask值组成:
027
vim /etc/profile
/022
then:umask可以改
vim /etc/bashrc
/022

cat /etc/shadow
chage -M 时间 修改最长有效时间
vim /etc/log
vim /etc/login.defs
:set nu 25行
PASS_MAX_DAYS 90
useradd testuser
id testuser
passwd -S testuser

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想成为前端工程师滴小小白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值