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 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
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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 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 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 at 11:21
    
Is your user the owner of the file sample.txt? –  Charo Jun 24 at 11:24
    
Yes, i got it. it should be chown root:newgroup –  shantanu Jun 24 at 11:25
show 2 more comments

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.