特殊权限练习

[root@localhost ~]# useradd stu
[root@localhost ~]# su stu
[stu@localhost root]$ cat /etc/shadow
cat: /etc/shadow: 权限不够
[stu@localhost root]$ exit
exit
[root@localhost ~]# cat /etc/shadow
root:$1$hDJWFMdl$hfgaq.eQ1pWrODJV7jQmn1:16330:0:99999:7:::
bin:*:16325:0:99999:7:::
daemon:*:16325:0:99999:7:::
adm:*:16325:0:99999:7:::
lp:*:16325:0:99999:7:::
sync:*:16325:0:99999:7:::
shutdown:*:16325:0:99999:7:::
halt:*:16325:0:99999:7:::
mail:*:16325:0:99999:7:::
news:*:16325:0:99999:7:::
uucp:*:16325:0:99999:7:::
operator:*:16325:0:99999:7:::
games:*:16325:0:99999:7:::
gopher:*:16325:0:99999:7:::
ftp:*:16325:0:99999:7:::
nobody:*:16325:0:99999:7:::
nscd:!!:16325:0:99999:7:::
vcsa:!!:16325:0:99999:7:::
rpc:!!:16325:0:99999:7:::
mailnull:!!:16325:0:99999:7:::
smmsp:!!:16325:0:99999:7:::
pcap:!!:16325:0:99999:7:::
dbus:!!:16325:0:99999:7:::
avahi:!!:16325:0:99999:7:::
sshd:!!:16325:0:99999:7:::
rpcuser:!!:16325:0:99999:7:::
nfsnobody:!!:16325:0:99999:7:::
haldaemon:!!:16325:0:99999:7:::
avahi-autoipd:!!:16325:0:99999:7:::
xfs:!!:16325:0:99999:7:::
stu:!!:16357:0:99999:7:::
[root@localhost ~]# ls -l /etc/shadow
-r-------- 1 root root 889 10-14 18:55 /etc/shadow
[root@localhost ~]# sl -l /usr/bin/passwd
-bash: sl: command not found
[root@localhost ~]# ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 19904 2007-01-07 /usr/bin/passwd
[root@localhost ~]# ls -l /usr/bin/locate
-rwx--s--x 1 root slocate 22280 2009-09-04 /usr/bin/locate
[root@localhost ~]# ll /tmp
总计 0
[root@localhost ~]# ls -ld /tmp
drwxrwxrwt 4 root root 4096 10-14 18:36 /tmp
[root@localhost ~]# cd /tmp
[root@localhost tmp]# touch test
[root@localhost tmp]# ll
总计 4
-rw-r--r-- 1 root root 0 10-14 19:21 test
[root@localhost tmp]# chmod 777 test
[root@localhost tmp]# ll
总计 4
-rwxrwxrwx 1 root root 0 10-14 19:21 test
[root@localhost tmp]# su stu
[stu@localhost tmp]$ ll
总计 4
-rwxrwxrwx 1 root root 0 10-14 19:21 test
[stu@localhost tmp]$ rm test
rm: 无法删除 “test”: 不允许的操作
[stu@localhost tmp]$ exit
exit
[root@localhost tmp]# ll
总计 4
-rwxrwxrwx 1 root root 0 10-14 19:21 test
[root@localhost tmp]# rm test
rm:是否删除 一般空文件 “test”? y
[root@localhost tmp]# ll
总计 0
[root@localhost tmp]# su stu
[stu@localhost tmp]$ touch test1
[stu@localhost tmp]$ chmod 777 test1
[stu@localhost tmp]$ ll
总计 4
-rwxrwxrwx 1 stu stu 0 10-14 19:23 test1
[stu@localhost tmp]$ exit
exit
[root@localhost tmp]# useradd stu2
[root@localhost tmp]# su stu2
[stu2@localhost tmp]$ ll
总计 4
-rwxrwxrwx 1 stu stu 0 10-14 19:23 test1
[stu2@localhost tmp]$ rm test1
rm: 无法删除 “test1”: 不允许的操作
[stu2@localhost tmp]$ exit
exit
[root@localhost tmp]# ll
总计 4
-rwxrwxrwx 1 stu stu 0 10-14 19:23 test1
[root@localhost tmp]# rm test1
rm:是否删除 一般空文件 “test1”? y
[root@localhost tmp]# ll
总计 0
[root@localhost tmp]# umask
0022
[root@localhost tmp]# touch test
[root@localhost tmp]# ll
总计 4
-rw-r--r-- 1 root root 0 10-14 19:30 test
[root@localhost tmp]# chmod 4755 test;ll test
-rwsr-xr-x 1 root root 0 10-14 19:30 test
[root@localhost tmp]# chmod 6755 test;ll test
-rwsr-sr-x 1 root root 0 10-14 19:30 test
[root@localhost tmp]# chmod 1755 test;ll test
-rwxr-xr-t 1 root root 0 10-14 19:30 test
[root@localhost tmp]# chmod 7666 test;ll test
-rwSrwSrwT 1 root root 0 10-14 19:30 test
[root@localhost tmp]#

 

转载于:https://www.cnblogs.com/cphome/p/5095693.html

### Linux 权限管理教程 #### 文件目录权限概述 Linux 中的每一个文件目录都具有特定的所有者、所属其他用户的访问权限设置。这些权限决定了谁可以读取、写入或执行该文件或进入该目录。 - **所有者 (User)**:创建文件的用户,默认拥有最高控制权。 - **所属 (Group)**:与文件关联的一用户,通常由管理员分配。 - **其他人 (Others)**:既不是所有者也不是所属成员的任何用户[^1]。 #### 查看文件权限 要查看某个文件的具体权限信息,可使用 `ls -l filename.txt -rw-r--r-- 1 user group 0 Jan 27 14:35 filename.txt ``` 上述输出中 `-rw-r--r--` 表示: - 第一位字符表示文件类型(此处为常规文件) - 接下来的三位代表所有者的权限 (`rw-`) - 再之后三位代表同内其他人的权限 (`r--`) - 最后三位则对应于除前两者之外的人(`r--`) 的权限 #### 修改文件权限 通过 `chmod` 可更改现有文件上的权限位。此命令接受两种形式的参数输入——符号模式八进制数值模式。 ##### 符号模式修改权限 允许增减指定角色对于目标对象拥有的某些权利: ```bash # 添加所有人对 file.txt 的执行权限 $ chmod a+x file.txt # 移除除了所有者外任何人对 dir/ 下的内容列表浏览能力 $ chmod o-rwx,g-wx dir/ ``` ##### 数字方式设定权限 每种类型的权限可以用三个数字来表达,范围是从0到7: | Number | Permission | |--------|------------| | 0 | --- | | 1 | --x | | 2 | -w- | | 3 | -wx | | 4 | r-- | | 5 | r-x | | 6 | rw- | | 7 | rwx | 例如给定一个新文档设初始状态为只允许可读不可改也不运行,则应为其赋予值 '4': ```bash $ touch newfile && chmod 400 newfile ``` #### 更改所有权及群归属 利用 `chown` `chgrp` 工具能够调整文件或整个树状结构下的项目属性至新的主体身份或是群体分类下: ```bash # 将文件 ownership 改变给另一名用户 $ sudo chown anotheruser:newgroup some_file_or_directory/ # 单独改变某物隶属之团体名称而不影响其主人翁地位 $ sudo chgrp developers project_folder/ ``` #### 设置默认继承父级权限 为了简化管理保持一致性,在创建子项时自动应用来自上级容器的安全策略是非常有用的特性之一。这可以通过设置特殊标志 Sticky Bit 或者是在 NFS 上启用 ACLs 实现更复杂的规则集[^2]: ```bash # 对 /path/to/dir 应用 sticky bit, 新建于此内的条目会保留原始创作者的身份作为个体占有者 $ chmod +t /path/to/dir ``` #### 用户密码变更实践 尽管这不是严格意义上的权限管理部分,但是了解如何安全有效地更新个人账户凭证也是至关重要的技能点。借助内置工具 `passwd`, 普通用户即可自行完成这项工作而无需求助超级管理员介入[^4]: ```bash # 更新当前登录账号的新口令 $ passwd Changing password for user. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值