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 have a root account from which I do all of my tasks. I set up my partitions to mount at startup. I have also created an account for my younger brother. I do not want him to access specific partitions, while still having access to others.

I have:

  • sda5
  • sda6
  • sda7

I want to block access to sda5 but want to give him permission to access the other sda partitions. How can I do that?

share|improve this question

4 Answers 4

up vote 3 down vote accepted

Thanks for the help guys. Both the answers helped me find out what I need to do. Here's what I have done.

My other sda are ntfs file system so I cannot directly change permission. So I have to mount it in a folder to which only I have access.

I make a folder in /media named secret with terminal

cd /media
sudo mkdir -p secret

Then I change ownership of this folder with chown command.

sudo chown XXXX:XXXX /media/secret

Where XXXX in my user name. Then I changed permission to that folder so that only I can access.

sudo chmod 700 /media/secret

Then I had to edit /etc/fstab for appropriate mounting point of sda5.

gksudo gedit /etc/fstab

Then add

/dev/sda5        /media/secret  ntfs defaults           0  0

at the end and saved it. Then reboot.

Viola! It worked.

share|improve this answer

Assuming your friend's name is Alice and she already has an account on your system, you can set up your drives such that they are automatically mounted with your ideal configuration. This is done by editing /etc/fstab.

non-ext4

The permissions for the drive may be determined completely within /etc/fstab for most filesystems.

Add the following to your /etc/fstab

/dev/sda5 /mnt/Secret ext3 defaults 0 0
/dev/sda6 /mnt/Shared ext3 defaults,uid=1000,gid=1000 0 0

You can determine a user or group's ID by looking at /etc/passwd or /etc/group.

ext4

ext4 does not allow uid/gid options. You will set the permission by changing the mount directories' rights.

Add the following to your /etc/fstab

/dev/sda5 /mnt/Secret ext4 defaults 0 0
/dev/sda6 /mnt/Shared ext4 defaults 0 0

Assign the permissions

chown root:root /mnt/Secret
chmod 770 /mnt/Secret
chown alice:alice /mnt/Shared
chmod 777 /mnt/Shared

You could also create a group of users, such as shared, and only give that group permissions for the drive.

share|improve this answer
    
Thanks for your help. –  Kaktarua Jul 19 '12 at 13:43

If it has the right filesystem, you can change the permissions of the folder where it is mounted. For example, if it is mounted as /media/sda5, you need to type the following at the terminal (Ctrl+T).

sudo chown your_username:your_username /media/sda5
sudo chmod 700 /media/sda5

This will allow only the user specified by your_username, as well as the root user, to access the files. This will not work for some filesystems, such as NTFS. In that case, you will need to change the permissions of the parent directory. For example, if you have mounted it as /media/private/sda5, you will need to apply the operations to the /media/private directory. This will restrict access.

share|improve this answer
    
Thank you buddy. –  Kaktarua Jul 19 '12 at 13:43

My solution will be simple.

  • Open the /etc/fstab file with root permission.
  • Add this line and save and close the file.

    /dev/sda5 /media/secret ntfs defaults 0 0
    
  • Then anytime he wants to mount it, it will ask for password, which only you know. So, safe and easy. You can mount it easily with terminal

    sudo mount /dev/sda5
    

For the other partitions, both user can mount them via nautilus easily. or as you said, You have a setting to mount them automatically. That's it. Only the setting for /dev/sda5 need to be changed.

It's easy, isn't it?


As a comment from Eliah Kagan suggests that, the non-root users can still mount it. IMHO it is actually no. Even admin users can't mount the partitions without giving explicitly their password in terminal.

I tested this:

I have an ntfs partition which is /dev/sda3. I created an entry in /etc/fstab like this one:

 /dev/sda3   /media/works  ntfs   defaults  0   0

The result is, when I tried to execute it via nautilus, this error message is displayed.

enter image description here

When I tried to mount it via terminal with udisks --mount /dev/sda3 , this error message is displayed

Mount failed: Error mounting: mount exited with exit code 1: helper failed with:
mount: only root can mount /dev/sda3 on /media/works

So, It actually prevents non-root users, even the root users. They can only mount it via mount command and giving the password as below:

 sudo mount /dev/sda3
share|improve this answer
    
This solution does not take into account the permissions issue mentioned in the OP. –  earthmeLon Jul 19 '12 at 17:44
    
@earthmeLon How? –  Anwar Shah Jul 19 '12 at 17:47
    
Ok. Its easy. But i want to mount it at boot time. –  Kaktarua Jul 20 '12 at 23:07

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.