I want every user to have full permissions over a single directory(and all the contents). Is this possible, and how? Thanks.
3 Answers
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.
- 10,737
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
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:
group1can be created using following command:sudo addgroup group1user1can be added togroup1using following command:sudo adduser pandya group1Now permissions can be applied using following commands:
sudo chown :group1 -R dir1 sudo chmod g+rwx group1
Explanation:
sudo chown :group1 -R dir1will applygroup1todir1recursively by-R(to all sub directories and files)sudo chmod g+rwx group1will apply read+write+execution permission togroup1- As
user1is ingroup1so-that nowuser1has full permission viagroup1fordir1recursively!
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.
- 37,289