我使用的是 Ubuntu 12.04。我有 4 个 NTFS 分区。我创建了 2 个用户:一个是我自己(管理员),一个是家人(标准/非管理员)。
我成功限制了此标准用户对我的主文件夹的访问。现在我想限制它访问我的所有 NTFS 分区。我该怎么做?
我检查了限制其他用户对 NTFS 分区的访问但是虽然答案被接受了,但正如后来的评论所见,它似乎也没有对原帖者有所帮助。
答案1
使用以下命令打开 fstab 文件
gksudo gedit /etc/fstab
您应该在 /etc/fstab 文件中添加如下行,
/dev/sda7 /media/EXTRA ntfs-3g noauto,uid=XXX,unmask=7 0 0
这
XXX
是我的用户 ID。您可以使用id
命令找到您的用户 ID,这/dev/sda7
是我想要限制访问的分区。创建一个名为的文件夹
EXTRA
,/media/
如下所示,sudo mkdir /media/EXTRA
现在,无论何时登录,您都需要将其安装为,
sudo mount /dev/sda7 /media/EXTRA
完毕!
解释:
如果特定分区包含 VFAT 或 NTFS 文件系统,并且您只希望自己能够访问它,则非常简单:
在 fstab 行中包含选项"noauto", "uid=XXX", and "umask=7"
并删除“用户”和/或“用户”选项(如果它们现在出现)。
这意味着在启动时系统将出现该分区卸载,并且只有您(以 root 身份操作,大概使用 sudo)可以挂载它。
一旦挂载,它将归您的非特权用户所有(假设该用户的 uid 为 XXX,该 ID 是在 MDV 安装中安装时创建的第一个用户 - 使用以该用户身份运行的“id”命令进行检查,并相应地调整 fstab),并且所有其他本地用户都无法访问。
通过发出mount
四次命令来挂载您受限制的 4 个分区是一项无聊的任务。为了减少这项无聊的任务,我编写了一个 shell 脚本:
#!/bin/bash
#Mount Unmount secret partitions now with choice of partition
function checkPartitions(){
local state=$1
local dev=$2
case $state in
"unmounted")
mount | grep -q $dev
if [ $? -eq 1 ]; then
echo $dev
fi
;;
"mounted")
mount | grep -q $dev
if [ $? -eq 0 ]; then
echo $dev
fi
;;
esac
}
function safeUnmount() {
local dev=$1
mount | grep -q $dev
if [ $? -eq 0 ]; then
echo "Device $dev found. Unmounting now"
sudo umount $dev
if [ $? -eq 0 ]; then
echo "Device $dev unmounted successfully."
else
echo "You are not root??"
fi
else
echo "Device $dev is already unmounted."
fi
}
function safeMount() {
local dev=$1
mount | grep -q $dev
if [ $? -eq 1 ]; then
echo "Device $dev not found. Mounting now"
sudo mount $dev
if [ $? -eq 0 ]; then
echo "Device $dev mounted successfully."
else
echo "You are not root??"
fi
else
echo "Device $dev is already mounted."
fi
}
echo -e "What you want to do? \n 1. Mount Secret Partitions \n 2. Unmount Secret Partitions"
read -p "Enter your choice :" choice
case $choice in
1)
echo -e "You want to Mount your secret partitions"
echo "-------List of Unmounted secret partitions-------"
checkPartitions "unmounted" "/dev/sdaX1"
checkPartitions "unmounted" "/dev/sdaX2"
checkPartitions "unmounted" "/dev/sdaX3"
checkPartitions "unmounted" "/dev/sdaX4"
anythingelse="y"
#echo -e "\n"
while [ $anythingelse == y -o $anythingelse == Y ]; do
read -p "Which partition should be mounted?" partNum
safeMount "/dev/sda"$partNum
read -p "Do you want to mount any other partition? [y/n]" anythingelse
done
;;
2)
echo -e "You want to Unmount your secret partitions\n"
echo "--------List of Mounted secret partitions--------"
checkPartitions "mounted" "/dev/sdaX1"
checkPartitions "mounted" "/dev/sdaX2"
checkPartitions "mounted" "/dev/sdaX3"
checkPartitions "mounted" "/dev/sdaX4"
anythingelse="y"
#echo -e "\n"
while [ $anythingelse == y -o $anythingelse == Y ]; do
read -p "Which partition should be unmounted?" partNum
safeUnmount "/dev/sda"$partNum
read -p "Do you want to unmount any other partition? [y/n]" anythingelse
done
;;
esac
/dev/sdaX
用 4 个分区替换。
另存为secret-mount-unmount.sh
然后发出命令
chmod +x /path/to/file/secret-mount-unmount.sh
双击该文件然后点击Run in Terminal
继续。
答案2
您需要添加 NTFS 分区到/etc/fstab
通过运行获取设备 ID
sudo blkid
。(例如 /dev/sda1)通过运行创建挂载点
sudo mkdir /media/mount-point
。(例如 /media/windows)编辑
fstab
。sudo nano /etc/fstab
添加此行:
/dev/sda1 /media/windows ntfs-3g noauto,user,uid=1000,gid=1000,umask=0027 0 0
并点击保存ctrl+o
,然后点击退出ctrl+x
您也可以参考这里: https://help.ubuntu.com/community/Fstab