如何在linux中为ntfs分区中的文件设置不可执行的权限?

如何在linux中为ntfs分区中的文件设置不可执行的权限?

进入文件系统为ext4的debian:

vim /tmp/sphinx.rst

sphinx tutorial
=====================
installation
---------------
::

 sudo apt-get install python3-sphinx

create a new project
--------------------------
::

    mkdir  mydoc
    cd mydoc
    sphinx-quickstart

显示sphinx.rst权限:

ls -al   sphinx.rst
-rwxrwxrwx 1 debian debian 261 Aug 17 11:54 sphinx.rst

输入绝对路径即可执行/tmp/sphinx.rst

/tmp/sphinx.rst
/tmp/sphinx.rst: line 1: sphinx: command not found
/tmp/sphinx.rst: line 2: ====================================================================: command not found
/tmp/sphinx.rst: line 3: installation: command not found
/tmp/sphinx.rst: line 4: ---------------: command not found
/tmp/sphinx.rst: line 5: ::: command not found
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  python-babel-localedata python3-alabaster python3-babel python3-imagesize
  python3-jinja2 python3-markupsafe sphinx-common
Suggested packages:
  python-jinja2-doc python3-sphinx-rtd-theme dvipng sphinx-doc
The following NEW packages will be installed:
  python-babel-localedata python3-alabaster python3-babel python3-imagesize
  python3-jinja2 python3-markupsafe python3-sphinx sphinx-common
0 upgraded, 8 newly installed, 0 to remove and 46 not upgraded.
Need to get 4,408 kB of archives.
After this operation, 23.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

将其权限改为644,即可执行。

sudo chmod 644  sphinx.rst
/tmp/sphinx.rst
bash: /tmp/sphinx.rst: Permission denied

sdb2格式为ntfs

sudo blkid |grep sdb2
/dev/sdb2: LABEL="winntfs" UUID="284A29774A2942C4" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="292c184b-766f-4036-8fa0-5bcd936b85c2"

使用以下命令安装它/mnt/winntfs

sudo mount /dev/sdb2  /mnt/winntfs

将分区复制到分区/tmp/sphinx.rst中。ext4ntfs

cp /tmp/sphinx.rst /mnt/winntfs
ls -al  /mnt/winntfs/sphinx.rst
-rwxrwxrwx 1 root root 261 Aug 17 12:02 /mnt/winntfs/sphinx.rst
sudo chmod 644 /mnt/winntfs/sphinx.rst
ls -al  /mnt/winntfs/sphinx.rst
-rwxrwxrwx 1 root root 261 Aug 17 12:02 /mnt/winntfs/sphinx.rst

我的debian里无法修改文件的模式,现在重启进入win10,将其权限设置为read and write,不包含任何内容execute

在此处输入图片描述

重启后重新进入debian,重新mount dev/sdb2/mnt/winntfs/sphinx.rst还能执行,如何给sphinx.rstlinux中的ntfs分区中的文件设置不可执行的权限?

答案1

默认情况下,ntfs-3g 驱动程序会忽略实际的 NTFS 权限并始终显示固定值(如 vfat 驱动程序)。您可以使用挂载选项 、 等更改这些fmask=0133uid=1000

要激活完整的 chown/chmod 支持,您需要使用该选项进行挂载-o permissions或创建有效的 .NTFS-3G/UserMapping 文件。

答案2

mount和命令中都不ntfs-3g包含和file_mode=中的参数。man mountman ntfs-3g

sudo mount -o permissions /dev/sdb2  /mnt/winntfs

或者

sudo ntfs-3g -o permissions /dev/sdb2  /mnt/winntfs  

它们的效果是一样的,然后你可以用设置文件模式sudo chmod 644 /mnt/winntfs/sphinx.rst,它无法执行。

相关内容