目录里面的shell脚本有执行权限, 执行报权限不足—分析mount的几个选项的作用

系统+安全 Liemer_Lius 775℃

今天, 遇到一个问题. 不知道是谁, 在维护中将/tmp目录的挂在选项改了, 导致有执行权限的脚本无法直接绝对路径或者相对路径执行.

经过专家定位, 发现/tmp目录的挂在选项中加入了noexec, 导致脚本即使有执行权限, 仍然没有执行的能力; 将该选项去掉后, 重新挂在后恢复.

 

下面, 就重点分析一下mount的各个选项的作用:

命令使用格式:mount [-fnrsvw] [-t vfstype] [-o options] device dir

Device部分指的是挂载的设备名:

(1) 设备文件:例如/dev/sda5
(2) 卷标:-L 'LABEL', 例如 -L 'MYDATA'
(3) UUID, -U 'UUID':例如 -U '0c50523c-43f1-45e7-85c0-a126711d406e'
(4) 伪文件系统名称:proc, sysfs, devtmpfs, configfs

常用的命令选项:

-t vsftype:指定要挂载的设备上的文件系统类型;
-r: readonly,只读挂载;
-w: read and write, 读写挂载;
-n: 不更新/etc/mtab; 
-a:自动挂载所有支持自动挂载的设备;(定义在了/etc/fstab文件中,且挂载选项中有“自动挂载”功能)
-L 'LABEL': 以卷标指定挂载设备;
-U 'UUID': 以UUID指定要挂载的设备;
-B, --bind: 绑定目录到另一个目录上;

-o挂载选项:

async:异步模式;
sync:同步模式;
atime/noatime:包含目录和文件;
diratime/nodiratime:目录的访问时间戳
auto/noauto:是否支持自动挂载
exec/noexec:是否支持将文件系统上应用程序运行为进程
dev/nodev:是否支持在此文件系统上使用设备文件;
suid/nosuid:是否支持在此文件系统上使用特殊权限
remount:重新挂载,不影响现在的挂载点以及资源,可在线重新挂载
ro:只读
rw: 读写
user/nouser:是否允许普通用户挂载此设备
acl:启用此文件系统上的acl功能

-o缺省挂载选项:

defaults:rw, suid, dev, exec, auto, nouser, and async
remount
Attempt  to  remount  an already-mounted filesystem.  This is commonly used to change the mount flags for a filesystem, especially to make a readonly filesystem writable.
It does not change device or mount point.

The remount functionality follows the standard way the mount command works with options from fstab.  This means that mount does not read fstab (or mtab)  only  when  both device and dir are specified.

mount -o remount,rw /dev/foo /dir  # 带资源的挂载,会覆盖/etc/fstab中的挂载选项;
After  this  call  all old mount options are replaced and arbitrary stuff from fstab (or mtab) is ignored, except the loop= option which is internally generated and maintained by the mount command.

mount -o remount,rw  /dir          # 不带资源的挂载命令,会将命令行中-o指定的flag和/etc/fstab中的flag做合并;
After this call, mount reads fstab and merges these options with the options from the command line (-o).  If no mountpoint is found in fstab, then a remount with unspecified source is allowed.

 

转载请注明:liutianfeng.com » 目录里面的shell脚本有执行权限, 执行报权限不足—分析mount的几个选项的作用

喜欢 (1)

评论已关闭。