Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am using Ubuntu 12.04. I have 4 NTFS partitions. I have made 2 users: One for myself (Admin) and one for family (standard/non-admin).

I successfully restricted the access to my home folder from this standard user. Now I want to restrict it from accessing ALL my NTFS partitions. How can I do this?

I checked Restrict access from another user to the NTFS partition but though the answer is accepted it doesn't seem to have helped that OP either as seen in the comments later.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
  1. Open fstab file as using

    gksudo gedit /etc/fstab
    
  2. You should add line in /etc/fstab file as follows,

    /dev/sda7   /media/EXTRA    ntfs-3g noauto,uid=XXX,unmask=7 0   0
    

    Here XXX is my user id. You can find yours with id command and /dev/sda7 is the partition I want to restrict access to.

  3. Create a folder named EXTRA in /media/ as follows,

    sudo mkdir /media/EXTRA
    
  4. Now whenever you login you need to mount it as,

    sudo mount /dev/sda7 /media/EXTRA
    

Done!

Explanation:
If a particular partition contains a VFAT or NTFS filesystem and you only wish to be able to access it yourself, it's pretty simple:

Include the options "noauto", "uid=XXX", and "umask=7" in fstab line and remove the "user" and/or "users" options if they appear there now.

This means that at boot time the system will come up with that partition unmounted, and only you (operating as root, using sudo presumably) can mount it.

Once mounted, it will be owned by your unprivileged user (assuming that that user's uid is XXX, which is given to the first user created at install time in MDV installs - check with the "id" command run as that user, and adjust fstab accordingly) and will be inaccessible to all other local users.


To mount your restricted 4 partitions by issuing mount command four times is a boring task. To cut that boring task, I have written a shell script:

#!/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

Replace /dev/sdaX with your 4 partitions.

Save as secret-mount-unmount.sh and then issue a command

chmod +x /path/to/file/secret-mount-unmount.sh

Double click the file and then hit Run in Terminal and proceed.

share|improve this answer
    
For future reference, when you add a comment with details, please edit it into your answer/question. –  jrg May 24 '12 at 12:52
    
umm...one more thing...i mean m just asking...if possible...can a GUI be made for this??If its easy and simple?? :o –  Nirmik May 24 '12 at 19:12
add comment

You need to add NTFS partition to /etc/fstab

  1. Get device id by running sudo blkid. (Eg. /dev/sda1)
  2. Create mount point by running sudo mkdir /media/mount-point. (Eg. /media/windows)
  3. Edit fstab.

    sudo nano /etc/fstab

Add this line: /dev/sda1 /media/windows ntfs-3g noauto,user,uid=1000,gid=1000,umask=0027 0 0

and save by clicking ctrl+o, then exit by clicking ctrl+x

You can also refer here: https://help.ubuntu.com/community/Fstab

share|improve this answer
    
replace device id and mount point with your own. –  dixoncx May 23 '12 at 12:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.