7

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.

6

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 .
  • thanq this exactly what i want. – Necktwi Nov 24 '12 at 4:36
7

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.

  • 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
0

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

login <username>:<group>
  • 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

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.