3

I have created a group named newgroup. But I didn't add my user to this group. Now I want give the write permission to this group for a specific file named sample.txt. I can use chmod if I am the member of this newgroup. Can I do this using sudo? How? I created this group using the following command

sudo groupadd newgroup
0
10

First, execute

sudo chown root:newgroup sample.txt

In that way you will change the owner of file sample.txt to be root and the group of this file to be newgroup.

Then run

sudo chmod g+w sample.txt
7
  • Thank you for quick reply. Will This chmod command change the permission for all groups or the groups related to my username? – shantanu Jun 24 '14 at 10:04
  • With the first command, the file sample.txt will belong to the group newgroup, so the chmod command add write permission only to this group. – Charo Jun 24 '14 at 10:12
  • But still i can read/write the file from my user without sudo. I am not the member of newgroup. Nobody is the member of newgroup. I run chmod 775 simple.txt after chown :newgroup simple.txt. I should not be able to modify the file from my user. But i can. Because still i am the owner of this file. user field in chmod is unavailable – shantanu Jun 24 '14 at 11:21
  • 1
    That is, if you want root be the owner ot the file sample.txt. – Charo Jun 24 '14 at 11:26
  • 1
    Let's improve the answer a little bit... – Charo Jun 24 '14 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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