0

I want every user to have full permissions over a single directory(and all the contents). Is this possible, and how? Thanks.

2
  • Do you mean the guest session account or did you create a separate guest user account? Aug 2, 2014 at 15:52
  • It's not a big deal if a guset has acces to this folder, but it's better that it doesn't. I mean real guest account, which you get when you install ubuntu. Aug 2, 2014 at 21:20

3 Answers 3

4

As the guest session user does not get added to the users group you could simply do the following:

sudo chown -R $USER:users /var/privatefolder

sudo chmod -R 770 /var/privatefolder

The guest session user could then not access the contents of /var/privatefolder

Edit

Looks like users created in GUI or at installation are not added to Users group automatically. I assumed this to be true.

you would have to sudo usermod -a -G users username

This would need you to add users to the group manually thus making this answer by TuKsn just as easy.

14
  • I enter this and I cannot see the contents of directory. Please, help. Aug 2, 2014 at 19:04
  • You as in the user? or you as in the Guest. can you please show the output of ls -l /path/to/folder
    – squareborg
    Aug 2, 2014 at 19:09
  • ls: cannot open directory /opt/D3GO/: Permission denied Aug 2, 2014 at 19:52
  • ls -l /opt/ | grep D3GO
    – squareborg
    Aug 2, 2014 at 19:59
  • drwxrwx--- 5 root users 4096 авг 2 20:24 D3GO Aug 2, 2014 at 20:49
2

You can get what you want to with adding users in particular group and then applying full permission to that group.

(echo $USER & echo $LOGNAME is helpful to get username and logname)

Example:

If/Let:

dir1 is directory to which you want to apply full permission to user,
user1 is user to which you want to give full permission,
group1 is existing or to be create for giving full permission.

Then following command-line information can help you:

  1. group1 can be created using following command:

    sudo addgroup group1
    
  2. user1 can be added to group1 using following command:

    sudo adduser pandya group1
    
  3. Now permissions can be applied using following commands:

    sudo chown :group1 -R dir1
    sudo chmod g+rwx group1
    

Explanation:

  • sudo chown :group1 -R dir1 will apply group1 to dir1 recursively by -R (to all sub directories and files)
  • sudo chmod g+rwx group1 will apply read+write+execution permission to group1
  • As user1 is in group1 so-that now user1 has full permission via group1 for dir1 recursively!

Verification:

$ ls -ld dir1
drwxrwxr-x 3 pandya group1 4096 Aug  3 12:11 example

where drwxrwxr-x indicates d for directory 1st rwx for owner(u=pandya) permission 2nd rwx for group(g=group1) permission and r-x for other(o) permission in ugo manner.

2

You can create a group for all the user which should have access to this folder.

Create a new group:

sudo groupadd myNewGroup

Add a user to the group

sudo usermod -a -G myNewGroup username

Change user and group of the directory

sudo chown -R $USER:myNewGroup /path/to/dir/

Change the permissions of the directory

sudo chmod -R 770 /path/to/dir/

Or ug+rwx more info for permissions http://permissions-calculator.org/

Edit: As Shutupsquare suggest you can use the group users which already exists. To add all human users to the group you can use:

for u in $(awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd); do sudo usermod -a -G users $u; done  

based on: https://askubuntu.com/a/329689/265974

4
  • The problem is that I "don't know" the username as I intend to use this on a multiple computers with different usernames. If the guest can access the directory, that's actually not a problem. Aug 2, 2014 at 19:03
  • @DusanMilosevic: In that case you can simply make the directory "world writable": sudo chmod -R 777 /path/to/dir That won't automatically give write access to files created by other users, but everyone would be able to read everything. Aug 3, 2014 at 7:10
  • If it is not really necessary I would avoid 777 ...
    – TuKsn
    Aug 3, 2014 at 9:03
  • Yeah, that's not what I usually suggest either, but to me it sounds like it's what @DusanMilosevic asks for. Aug 3, 2014 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .