Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

i want to login as a member of non primary group to create files whose owner as a member of non primary group of current user.

-rwxr-xr-x 2 gowtham  gowtham      4096 Sep  5 14:48 defaultNewFile
drwxr-xr-x 2 gowtham  specificgrp  4096 Sep  5 14:50 requiredNewFile

i don't want to change group ownership after creation of file with chown.

I am more interested in login as a member of a non primary group.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Depending on why you want to do this, there may be another way.

If the setgid bit of a directory's permissions is set, then all files created in that directory will be owned by the same group that owns the directory.

$ chgrp specificgrp .
$ chmod g+s .
$ touch newfile
$ ls -l newfile
-rw-r--r-- 2 gowtham  specificgrp  4096 Sep  5 14:48 newfile
$ ls -ld .
drwxr-sr-x 2 gowtham  specificgrp  4096 Sep  5 14:48 .
share|improve this answer
    
thanq this exactly what i want. –  neckTwi Nov 24 '12 at 4:36

newgrp will help you out. See below for a walkthrough. Should speak for itself.

$ id
uid=1000(gert) gid=1000(gert) groups=1000(gert),4(adm),[...]
$ touch file1
$ newgrp adm
$ id
uid=1000(gert) gid=4(adm) groups=1000(gert),4(adm),[...]
$ touch file2
$ ls -al
[...]
-rw-rw-r--  1 gert gert     0 Nov 23 11:58 file1
-rw-rw-r--  1 gert adm      0 Nov 23 11:59 file2

Yes, this will change the primary group, but not permanently. Just for that session/shell, so in scripting this should not be an issue.

share|improve this answer
    
you r changing the primary group of the user. i want to do it with out changing the primary group. Thank you, i found the solution. i posted the answer. –  neckTwi Nov 24 '12 at 4:44

one can login in a shell as a member of specific group using

login <username>:<group>
share|improve this answer
    
its working to login in shell. But in my situation i am using ftp client to read or write files. i use sftp://user@host to login. sftp://user:group@host don't work. how to do it in case of ftp login?? –  neckTwi Nov 24 '12 at 4:56
1  
that's changing the primary group the same way as in my answer; temporarily for that session. –  gertvdijk Nov 24 '12 at 11:15

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.