特殊权限位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
相关文章
|
存储 NoSQL Java
数据类型-set 实现权限校验| 学习笔记
快速学习数据类型-set 实现权限校验
数据类型-set 实现权限校验| 学习笔记
|
1天前
|
存储 Java API
【数据结构】map&set详解
本文详细介绍了Java集合框架中的Set系列和Map系列集合。Set系列包括HashSet(哈希表实现,无序且元素唯一)、LinkedHashSet(保持插入顺序的HashSet)、TreeSet(红黑树实现,自动排序)。Map系列为双列集合,键值一一对应,键不可重复,值可重复。文章还介绍了HashMap、LinkedHashMap、TreeMap的具体实现与应用场景,并提供了面试题示例,如随机链表复制、宝石与石头、前K个高频单词等问题的解决方案。
14 6
【数据结构】map&set详解
|
1月前
|
存储 安全 Java
java集合框架复习----(4)Map、List、set
这篇文章是Java集合框架的复习总结,重点介绍了Map集合的特点和HashMap的使用,以及Collections工具类的使用示例,同时回顾了List、Set和Map集合的概念和特点,以及Collection工具类的作用。
java集合框架复习----(4)Map、List、set
|
30天前
|
Java
【Java集合类面试二十二】、Map和Set有什么区别?
该CSDN博客文章讨论了Map和Set的区别,但提供的内容摘要并未直接解释这两种集合类型的差异。通常,Map是一种键值对集合,提供通过键快速检索值的能力,而Set是一个不允许重复元素的集合。
|
1月前
|
存储 JavaScript 前端开发
ES6新特性(四): Set 和 Map
ES6新特性(四): Set 和 Map
|
29天前
|
存储 Java 索引