当前位置: 首页 > news >正文

12月21日 特殊权限与软、硬链接文件

一、三个特殊权限
set_uid 
含义:特殊权限SetUID 是指:当一个具有执行权限的文件设置SetUID权限后,用户执行这个文件时将以文件所有者的身份执行。该权限仅设置给二进制文件时才有具体作用,其余文件或文件目录设置此权限无意义。如passwd命令
示例:
12月21日 特殊权限与软、硬链接文件

(一)设置set_uid权限的方法:
同样使用chmod命令
12月21日 特殊权限与软、硬链接文件
12月21日 特殊权限与软、硬链接文件
这时普通用户就可以使用ls命令查看/root 文件目录里的内容了。
12月21日 特殊权限与软、硬链接文件
2、命令缺乏X权限时设置通过“chmod u=rws”设置set_uid权限时会变成rwS权限,但不影响效果。
12月21日 特殊权限与软、硬链接文件
12月21日 特殊权限与软、硬链接文件

(二)set_gid
含义:该权限对目录有效. 目录被设置该位后, 任何用户在此目录下创建的文件都具有和该目录所属的组相同的组. 
示例:
1)先查看/tmp/linux/文件夹的用户所属组,都是root。
12月21日 特殊权限与软、硬链接文件
我把他的所属组改为test1
12月21日 特殊权限与软、硬链接文件
2)这时我新建一个文件,他所属组仍然是root:
12月21日 特殊权限与软、硬链接文件
3)现在我给这个目录赋予set_gid权限,再新建一个文件
12月21日 特殊权限与软、硬链接文件
他的所属组就变成test1了。
12月21日 特殊权限与软、硬链接文件
这里对比3.txt和4.txt看的很明显。

(三)stick_bit
含义:除非目录的属主和root用户有权限删除它,除此之外其它用户不能删除和修改这个目录。
** wiki中的英文释义:** In computing, the sticky bit is a user ownership access right flag that can be assigned to files and directories on Unix-like systems.When a directory's sticky bit is set, the filesystem treats the files in such directories in a special way so only the file's owner, the directory's owner, or root user can rename or delete the file. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of the file's owner. Typically this is set on the /tmp directory to prevent ordinary users from deleting or moving other users' files.The modern function of the sticky bit was introduced in 4.3BSD[discuss] in 1986, and is found in most modern Unix-like systems.
系统中“/tmp/”目录自带该权限
12月21日 特殊权限与软、硬链接文件
给目录加上stick_bit
12月21日 特殊权限与软、硬链接文件
(四)查看文件或目录特殊权限位命令
ls -l命令
12月21日 特殊权限与软、硬链接文件
stat -c %a%A 
12月21日 特殊权限与软、硬链接文件
最前面这个数字表示uid、gid、stickybit情况,4=uid、2=gid、1=stickybit。所以也可以使用chmod+4700这种方式来设置文件的特殊权限。

二、软链接与硬链接
(一)含义
软链接:又叫符号链接,简单理解就是windows中的快捷方式,你删除原始文件会使软链接文件失效。软链接可以跨分区链接目录与文件,做软链接时尽量使用绝对路径。注意:软件链接文件不是一个独立的文件,它的许多属性依赖于源文件,所以给符号链接文件设置存取权限是没有意义的。
比如下面这个文件,文件头标识为l
12月21日 特殊权限与软、硬链接文件
wiki中的英文解释:Symbolic links are special files which when encountered during pathname resolution modify the pathname resolution to be taken to the location which the symbolic link contains. The content of the symbolic link is therefore the destination path string, which can also be examined using the readlink command line utility.[8] The symbolic link may contain an arbitrary string which does not refer to the location of an existing file, such a symbolic link will fail until a file is created at the location which is contained by the symbolic link. By contrast a symbolic link to an existing file will fail if the existing file is moved to a different location (or renamed).[5]

硬链接:与普通文件没什么不同,inode 都指向同一个文件在硬盘中的区块。注意,系统不支持对目录做硬链接。文件硬链接不能跨分区
wiki中的英文解释:Hard links also known simply as links are objects that associate the filename with the inode and therefore the file contents itself.[1] A given file on disk could have multiple links scattered through the directory hierarchy with all of the links being equivalent since they all associate with the same inode.[5] Creating a link therefore does not copy the contents of the file but merely causes another name to be associated with the same contents. Each time a hard link is created a link counter that is a part of the inode structure gets incremented; a file is not deleted until its reference count reaches zero.[1][6] Hard links can however only be created on the same file system; this can prove to be a particular disadvantage.

@一篇IBM网站上的文章”理解 Linux 的硬链接与软链接“能更好理解linux的文件系统。
(二)ln命令
ln命令用来为文件创件连接,连接类型分为硬连接和软连接两种,默认的连接类型是硬连接。如果要创建软连接必须使用"-s"选项。

语法:ln(选项)(参数)
选项:-s —symbolic:对源文件建立符号连接,而非硬连接;

示例:
1、给文件制作软链接文件
ln -s +原始文件 +软链接文件
12月21日 特殊权限与软、硬链接文件
结果
12月21日 特殊权限与软、硬链接文件

2、给目录制作软链接
12月21日 特殊权限与软、硬链接文件
12月21日 特殊权限与软、硬链接文件

3、创建文件的硬链接
12月21日 特殊权限与软、硬链接文件
12月21日 特殊权限与软、硬链接文件



 本文转自 whytl 51CTO博客,原文链接:http://blog.51cto.com/11934539/2053098

相关文章:

  • jquery.pagination.js分页插件的运用
  • 宋体、变量-Oracle存储过程基本语法-by小雨
  • Allot流量控制系统软件升级过程
  • FTP服务器配置与管理(2) 创建FTP站点
  • 局域网介质访问控制方法
  • javascript中toString跟toLocaleString的区别
  • 【转载】细聊分布式ID生成方法
  • IOS 关键字解读
  • 分布式mongodb搭建-主从搭建
  • PHPExcel 导出 excel
  • 重读杠杆阅读术
  • java 数字枚举
  • EX2T/EXT3文件系统
  • jQuery 2.0发布 不再支持IE 6/7/8
  • FTP服务器配置与管理(5) FTP用户隔离
  • $translatePartialLoader加载失败及解决方式
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • Angular 响应式表单之下拉框
  • eclipse的离线汉化
  • HTML中设置input等文本框为不可操作
  • Java 多线程编程之:notify 和 wait 用法
  • js
  • laravel5.5 视图共享数据
  • overflow: hidden IE7无效
  • Quartz初级教程
  • React-Native - 收藏集 - 掘金
  • Vue 动态创建 component
  • 道格拉斯-普克 抽稀算法 附javascript实现
  • 将回调地狱按在地上摩擦的Promise
  • 区块链技术特点之去中心化特性
  • 湖北分布式智能数据采集方法有哪些?
  • ​虚拟化系列介绍(十)
  • #HarmonyOS:Web组件的使用
  • #pragma pack(1)
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (day 2)JavaScript学习笔记(基础之变量、常量和注释)
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (笔试题)合法字符串
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (介绍与使用)物联网NodeMCUESP8266(ESP-12F)连接新版onenet mqtt协议实现上传数据(温湿度)和下发指令(控制LED灯)
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (三)mysql_MYSQL(三)
  • (一) springboot详细介绍
  • (一)RocketMQ初步认识
  • (原创)boost.property_tree解析xml的帮助类以及中文解析问题的解决
  • (转)Oracle存储过程编写经验和优化措施
  • .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
  • .net 受管制代码
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .Net程序猿乐Android发展---(10)框架布局FrameLayout
  • /proc/interrupts 和 /proc/stat 查看中断的情况
  • /var/log/cvslog 太大
  • @Builder用法
  • [20170705]diff比较执行结果的内容.txt
  • [ASP.NET MVC]Ajax与CustomErrors的尴尬