【CentOS 7笔记12】,几种特殊权限与软硬链接#171025

hellopasswd


一. 特殊权限

1. Set UID

[root@localhost ~]# which passwd    #/usr/bin/passwd
[root@localhost ~]# ls -l /usr/bin/passwd    #rwsr-xr-x红色目录,s为set_uid权限
[root@localhost ~]# ls -l /etc/shadow    #密码文件,无权限

而普通用户再修改passwd时有Set UID权限,当普通用户执行Set UID命令时,临时拥有root用户的权限,拥有改命令所有者的身份

切换到普通用户实验
[root@localhost ~]# su - user1

[user1@localhost ~]# whoami	#确认是否是再普通用户下,也可以看光标左侧主机名前的当前用户,这里使用普通用户为user1
[user1@localhost ~]# ls /root/	#尝试进入/root/目录,发现无权限
[user1@localhost ~]# ls -ld /root/	#r-xr-x---	蓝色
[user1@localhost ~]# which ls	#/usr/bin/ls
[user1@localhost ~]# ls -ld /usr/bin/ls	#rwxr-xr-x	绿色
[user1@localhost ~]# su -
passwd:

[root@localhost ~]# ls -ld /usr/bin/ls	#rwxr-xr-x	绿色
[root@localhost ~]# chmod u+s /usr/bin/ls
[root@localhost ~]# ls -ld /usr/bin/ls	#rwsr-xr-x	红色
[root@localhost ~]# su - user1

[user1@localhost ~]# ls /root/	#可查看
[user1@localhost ~]# ls -ld /root/	#r-xr-x---	目录权限没有变化
[user1@localhost ~]# ls -ld /usr/bin/ls	#rwsr-xr-x	红色
[root@localhost ~]# chmod u-s /usr/bin/ls    #撤销权限
[root@localhost ~]# chmod u=rws /usr/bin/ls    #rwSr-xr-x    红色    缺少x权限,同样也可以用
[root@localhost ~]# chmod u+x /usr/bin/ls    #rwsr-xr-x    红色

2. Set GID

切换到普通user1用户实验
[root@localhost ~]# su - user1

[user1@localhost ~]# ls /root/	#没有权限
[user1@localhost ~]# ls -l /usr/bin/ls	绿色
[user1@localhost ~]# su -
passwd:

[root@localhost ~]# chmod g+s /usr/bin/ls
[root@localhost ~]# su - user1

[user1@localhost ~]# ls /root/	#拥有临时权限
[user1@localhost ~]# ls -l /usr/bin/ls	黄色
[root@localhost ~]# mkdir /home/111
[root@localhost ~]# touch /home/1.txt
[root@localhost ~]# mkdir /home/111/222
[root@localhost ~]# touch /home/111/2.txt
[root@localhost ~]# ls -l /home/
    #rwxr-xr-x	111蓝色
    #rw-r--r--	1.txt白色
[root@localhost ~]# ls -l /home/111/
    #rwxr-xr-x	222蓝色
    #rw-r--r--	2.txt白色

[root@localhost ~]# chmod g+s /home/111/
[root@localhost ~]# ls -l /home/
    #rwxr-sr-x	111蓝色
    #rw-r--r--	1.txt白色
[root@localhost ~]# ls -l /home/111/
    #rwxr-xr-x	222蓝色
    #rw-r--r--	2.txt白色

[root@localhost ~]# mkdir /home/111/333
[root@localhost ~]# touch /home/111/3.txt
[root@localhost ~]# ls -l /home/111/
    #rwxr-xr-x	222蓝色
    #rw-r--r--	2.txt白色
    #rwxr-sr-x	333蓝色	#
    #rw-r--r--	3.txt白色
[root@localhost ~]# mkdir /home/111
[root@localhost ~]# chmod g+s /home/111
[root@localhost ~]# chown :hello /home/111
[root@localhost ~]# ls -l /home/111
    #rwxr-sr-x	user1	111蓝色

[root@localhost ~]# mkdir /home/111/222
[root@localhost ~]# touch /home/111/2.txt
[root@localhost ~]# ls -l /home/111/
    #rwxr-sr-x	user1	222蓝色
    #rw-r--r--	user1	2.txt

3. sticky bit

[root@localhost ~]# ls -ld /tmp/	#rwxrwxrwt	墨绿色
t为防删除位,指任何用户都可以在这个目录可读可写可执行,但必须为指定用户才可以删除,root用户除外
文件实验
在user1用户下:
cd /tmp/
touch 1.txt
ls -l
	#rw-rw-r-	1.txt白色
vi 1.txt
	写点东西
chmod 777 1.txt
ls -l 1.txt	#rwxrwxrwx	user1:user1	1.txt绿色
su - world

切换为user2用户
cd /tmp/
vi 1.txt	#可以修改
	写入东西
rm -f 1.txt	#提示不可删

作用是防止其他用户删除特定用户的权限,root用户除外
目录实验
user2用户
mkdir 111
chmod 777 111
ls -l 111	#rwxrwxrwx	墨绿色
su - user1

user1
cd /tmp/111/
touch 2.txt
mkdir 222
ls -l /111/
	#rw-rw-r--	2.txt白色
	#rwxrwxr-x	222蓝色
su - user2

user2
ls -l /111/
	#rw-rw-r--	2.txt白色
	#rwxrwxr-x	222蓝色
rm 2.txt	#可以删除
rm 222	#可以删除
ls -ld .	#rwxrwxrwx	world:world	.墨绿色

user2可删除user1在111目录里面的文件,得往上看父级目录的权限是谁
用法
chmod o+t 目录或文件
chmod o+rwtx 目录或文件

二.软链接与硬链接

1. 软链接

软链接方式
mkdir /tmp/1.txt
ln -s /tmp/1.txt /home/1.txt
ls -l /home
不建议使用相对路径,当文件发生移动时,会失去软链接的效果
mkdir /home/111
cd /home
ln -s 111 222
mv 222 /tmp/222    #闪红色,表示源文件不存在

使用绝对路径
mkdir /home/111
ln -s /home/111 /home/222
mv /home/222 tmp/222

为防止使用一些空间时被占满后写入失败,常常使用到了软链接方式存储将文件存储软链接到另一个地方

df -h
cp /boot/user1.log  /user1.log    #将/boot/的user.log软链接到根目录下
rm /boot/user1.log ; ln -s /user1.log /boot/user1.log ;    #删除并把根目录的user1.log做软链接到/boot/目录下
ls -l /boot/

2. 硬链接

硬链接不支持对目录操作

touch 1.txt
ln 1.txt 1_heard.txt
ln -s 1.txt 1_sorft.txt
ls -l .
ls -i	#查看inode号
rm 1.txt
ls -l .
硬链接的inode号与源文件相同
硬链接无法跨分区

【CentOS 7基础笔记10】cp、mv、文档查看方式
【CentOS 7基础笔记11】,目录权限,所有者与所有组,隐藏权限
【CentOS 7基础笔记12】,几种特殊权限与软硬链接
【CentOS 7基础笔记13】,find用法和文件传输
【CentOS 7基础笔记14】,其他

修改于171025

转载于:https://my.oschina.net/hellopasswd/blog/1555994

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值