[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 #密码文件,无权限
切换到普通用户实验 [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 红色
切换到普通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
[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 目录或文件
软连接方式 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
为防止使用一些空间时被占满后写入失败,经常使用到了软连接方式存储将文件存储软连接到另外一个地方node
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/
硬连接不支持对目录操做ui
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号与源文件相同 硬连接没法跨分区