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 want to have a few folders on a partition whose contents I can freely edit, but outside nothing should be saved.

Specifically, I want the folders in my Home (Documents, Music, etc) on a different partition, but rest of the normally hidden folders remain in the main partition with Ubuntu. I can make the files within the Home folders save in another partition using fstab binding, but I still can't think of how to lock the partition from edits outside those folders. I'm open to suggestions of alternatives to binding - but please, no symbolic links.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Where do you want to prohibit write access - it's unclear. As user oxwivi you aren't allowed to write to /lib, /usr, /var, /bin and so on, but sudo needs write access for updates.

Or the configuration needs to changed in /etc.

And there are dynamic folders /proc /sys /dev , while logfiles are written to /var/log and so on ...

And every user needs write access to /tmp


(Edit after diskussion)

chmod a-w -R /partition
chmod u+w /partition/1 /partition/2
  • a-w means 'all (user, group, others) - := remove permission to w(rite).
  • -R means: recursively, for directories/files therein.
  • u+w := add write-permission for the user who is owner.

In front of +and-, you may use ugo for user, who is the owner, group and others (problem: confusion o?owner/other) or a for all. +- means to add or revoke permissions, = means to set them. rwx are acronyms for read, write and execute.

This are the mostly used ones. More details in man chmod.

chmod ug+rw foo.txt 

adds read-write permissions for user and group.

chmod o=x bar.txt 

sets the permission to execute for others.

share|improve this answer
    
Let's say that /partition is the directory to the partition in question. I don't want anything to be able to be written except inside the folders named 1 and 2. So the only way I can write something to the partition is by saving inside /partition/1 and /partition/2 - nothing will be written directly to /partition/ directory. –  Oxwivi Mar 3 '11 at 14:04
4  
chmod a-w -R /partition, chmod u+w /partition/1 /partition/2 - where is the problem? –  user unknown Mar 3 '11 at 14:28
    
@user unknown, the problem is that I did not know how to do it. And what's the difference between your commands and the ones in Amey's answer? There seems to be slight difference in the flags used. –  Oxwivi Mar 4 '11 at 11:58
    
u=rwx means: for the user who is the owner, set the permissions to r(ead), w(rite) and (e)x(ecute). a-w means 'all (user, group, others) - := remove permission to w(rite). -R means: recursively, for directories/files therein. u+w := add write-permission for the user who is owner. –  user unknown Mar 4 '11 at 19:46
    
@user unknown, please edit that into your answer - I don't want any users to read or write unlike the other answer. And will this permission setting affect live sessions? –  Oxwivi Mar 5 '11 at 5:55

You can give write access to these two fonder only. Apart from that do no give write access. So that user will not able to write elsewhere.

I would suggest you to give write access to partition1/folder1 and folder2.

chmod u=rwx partition1/folder1
chmod u=rwx partition1/folder2

Then I would suggest you to remove write access to partition1 folder

chmod u=rx partition1

Now you can not create any thing inside partition1 but you will be able to write into partition1/folder1 and 2.

xyz@xyz-desktop:~$ ls -lart|grep test1
dr-xr-xr-x  4 xyz xyz   4096 2011-03-03 19:51 test1
xyz@xyz-desktop:~$ ls test1
test3  test4
xyz@xyz-desktop:~$ ls -lart test1
total 16
drwxr-xr-x 61 xyz xyz 4096 2011-03-03 19:49 ..
drwxr-xr-x  2 xyz xyz 4096 2011-03-03 19:51 test4
dr-xr-xr-x  4 xyz xyz 4096 2011-03-03 19:51 . 
drwxr-xr-x  2 xyz xyz 4096 2011-03-03 19:51 test3
xyz@xyz-desktop:~$ touch ./test1/willItCreate
touch: cannot touch `./test1/willItCreate': Permission denied
xyz@xyz-desktop:~$ touch ./test1/test3/willItCreate
share|improve this answer
    
Will it affect Windows? –  Oxwivi Mar 3 '11 at 16:34
    
Windows is not linux, so Windows won't really care about those permissions. –  RolandiXor Mar 3 '11 at 20:03
    
@Roland, oh right, Windows won't even read ext filesystems in the first place. And next time you comment, please do tag @[user] or they'll miss the reply. And will the permission affect access from live sessions as well? –  Oxwivi Mar 4 '11 at 11:59
    
@Oxwivi Unfortunately not, live sessions can access everything on the device, because in a simple way of putting it, the live session does not know who the users on the drives are, and doesn't pay much attention to them. –  RolandiXor Mar 4 '11 at 18:53
    
@Roland, can it not be made to lock writing in the partition to all users? i.e. the lock does not specify any particular user, it's simply inaccessible to all. –  Oxwivi Mar 4 '11 at 19:02

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.