特殊权限位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
相关文章
|
3天前
|
Dart
Dart之集合详解(List、Set、Map)
Dart之集合详解(List、Set、Map)
9 1
|
8天前
|
存储 JavaScript 前端开发
JavaScript进阶-Map与Set集合
【6月更文挑战第20天】JavaScript的ES6引入了`Map`和`Set`,它们是高效处理集合数据的工具。`Map`允许任何类型的键,提供唯一键值对;`Set`存储唯一值。使用`Map`时,注意键可以非字符串,用`has`检查键存在。`Set`常用于数组去重,如`[...new Set(array)]`。了解它们的高级应用,如结构转换和高效查询,能提升代码质量。别忘了`WeakMap`用于弱引用键,防止内存泄漏。实践使用以加深理解。
|
3天前
|
Go
go语言map、实现set
go语言map、实现set
10 0
|
3天前
|
存储 消息中间件 算法
Java中的集合框架详解:List、Set、Map的使用场景
Java中的集合框架详解:List、Set、Map的使用场景
|
3天前
|
存储 自然语言处理 C++
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
11 0
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
|
7天前
|
存储 算法 NoSQL
C++一分钟之-map与set容器详解
【6月更文挑战第21天】C++ STL的`map`和`set`是基于红黑树的关联容器,提供有序存储和高效查找。`map`存储键值对,键唯一,值可重复;`set`仅存储唯一键。两者操作时间复杂度为O(log n)。常见问题包括键的唯一性和迭代器稳定性。自定义比较函数可用于定制排序规则,内存管理需注意适时释放。理解和善用这些工具能提升代码效率。
13 3