特殊权限位set_uid set_gid stick_bit 软链接硬链接

特殊权限位set_uid  set_gid   stick_bit  软链接硬链接

[root@alex ~]# ls -l /etc/shadow            存放密码文件  

----------. 1 root root 760 Oct 21 01:30 /etc/shadow

[root@alex ~]# ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 27832 Jun 10  2014 /usr/bin/passwd

[root@alex ~]# chmod u+s /usr/bin/ls                   临时拥有root权限的写法 

[root@alex ~]# ls -l /usr/bin/ls

-rwsr-xr-x. 1 root root 117656 Nov  6  2016 /usr/bin/ls

如下示例:   

[root@alex ~]# su - user

Last failed login: Thu Oct 26 22:22:13 CST 2017 from 183.206.173.194 on ssh:notty

There were 315 failed login attempts since the last successful login.

[user@alex ~]$ ls -l /root/        可以使用root的权限  

total 20

-rw-r--r--. 1 root root    0 Oct 26 09:22 2.txt

drw-r--r--. 2 root root 4096 Oct 25 08:49 3.txt

drwxr-xr-x. 2 root root 4096 Oct 16 14:01 c

drwxr-xr-x. 2 root root 4096 Oct 18 08:46 m

drwxr-xr-x. 2 root root 4096 Oct 24 09:36 p

drwxr-xr-x. 2 root root 4096 Oct 24 09:34 zx

[user@alex ~]$ ls /root/

2.txt  3.txt  c  m  p  zx

[root@alex ~]# chmod u-s /usr/bin/ls    更改原来的配置 

[root@alex ~]# ls -l /usr/bin/ls

-rwxr-xr-x. 1 root root 117656 Nov  6  2016 /usr/bin/ls

[root@alex ~]# chmod u=rws  /usr/bin/ls                              另外一种写法   

[root@alex ~]# ls -l /usr/bin/ls

-rwSr-xr-x. 1 root root 117656 Nov  6  2016 /usr/bin/ls

变成大S  因为没有x权限 大写的S也不受影响 也能执行

加上x权限就会变成小s   

[root@alex ~]# chmod u+x /usr/bin/ls     

[root@alex ~]# ls -l /usr/bin/ls

-rwsr-xr-x. 1 root root 117656 Nov  6  2016 /usr/bin/ls

[root@alex ~]# chmod u-s /usr/bin/ls       清楚的权限的写法  

[root@alex ~]# ls -l /usr/bin/ls

-rwxr-xr-x. 1 root root 117656 Nov  6  2016 /usr/bin/ls

set gid  可以作用在目录上也可以作用在子文件上,可以让普通用户临时拥有所属组的权限 

[root@alex ~]# chmod g+s  p

[root@alex ~]# mkdir p/2.txt      

[root@alex ~]# ls -l p

total 8

-rw-r--r--. 1 root root    0 Oct 26 22:49 1.txt

drwxr-sr-x. 2 root user 4096 Oct 26 22:51 2.txt

drwxr-xr-x. 2 root root 4096 Oct 26 22:50 nb

当set _gid   拥有组的权限  在他所在的组下面,创建的目录和文件用户所属组都是以该组名字定义   

stick_bit  防删除位

防止别人删除自己的文件 

加上防删除位

[root@alex ~]# su - user

Last login: Thu Oct 26 22:22:47 CST 2017 on pts/1

[user@alex ~]$ cd /tmp/

[user@alex tmp]$ cd

[user@alex ~]$ mkdir 1

[user@alex ~]$ chmod 777 1

[user@alex ~]$ ls -l

total 4

drwxrwxrwx. 2 user user 4096 Oct 26 23:09 1

[user@alex ~]$ cd 1

[user@alex 1]$ mkdir 2

[user@alex 1]$ touch 1.txt

[user@alex 1]$ ls -l

total 4

-rw-rw-r--. 1 user user    0 Oct 26 23:10 1.txt

drwxrwxr-x. 2 user user 4096 Oct 26 23:10 2

[user@alex 1]$ rm -r 2        这里体现可以删除 就是没有加防删除位  

[user@alex 1]$ ls -l

total 0

-rw-rw-r--. 1 user user 0 Oct 26 23:10 1.txt

[user@alex ~]$ chmod o+t 1      加上防删除位的用法 

[user@alex ~]$ ls -l

total 4

drwxrwxrwt. 2 user user 4096 Oct 26 23:10 1

[root@alex ~]# ln -s /tmp/alex/  /root/p     软链接的写法   

[root@alex ~]# ls -l /root/p

total 8

-rw-r--r--. 1 root root    0 Oct 26 22:49 1.txt

drwxr-sr-x. 2 root user 4096 Oct 26 22:51 2.txt

lrwxrwxrwx. 1 root user   10 Oct 26 23:25 alex -> /tmp/alex/       做成软链接

drwxr-xr-x. 2 root root 4096 Oct 26 22:50 nb

软链接  左边是你的源文件   右边才是软链接文件    

[root@alex ~]# ls -l x       相对路径还有绝对路径   

total 0

lrwxrwxrwx. 1 root root 2 Oct 26 23:30 nb -> nb

做软链接尽量使用绝对路径  

硬链接不支持对目录做硬链接 

硬链接相当于备份 ,即使删除一份 还有一份存在 。

硬链接有一个特性不能对目录做硬链接    

硬链接的实质就是通过文件的inode节点进行连接。我们都知道,Linux下每个文件都对应一个inode结点,都有一个单独的inode编号。而硬链接不同,每一个硬链接的inode都与源文件相同。假设我对文件A建立了一个硬链接文件B,此时B的inode编号与A相同。 

每个文件可以建立一个或多个硬链接,这样可以达到“防误删”的功能,当删除了源文件时,还可以通过硬链接文件来访问文件数据。 

文件可以做硬链接 前提不能跨分区  

ln  硬链接的写法  



本文转自 amenging 51CTO博客,原文链接:http://blog.51cto.com/11335852/1976722
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值