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 read the following about newgrp:

The newgrp command is used to change the current group ID during a
       login session. 

This made me think, how can I change my default's primary group permanently?

I imagine I can have a newgrp line in my startup files for my shell, but is there a way to change my primary ID for every login session without resorting to newgrp?

I am interested in a generic solution, but in case it depends on the distribution, I am interested in solutions for Ubuntu 11.10 and for Red Hat Enterprise Linux Server (I have administrator priviledges in the former, but not in the latter).

Addendum:

From the great answer @Shawn provided below to the these questions, I read "I won't be able to do this without root privileges".

This made me wonder: why? Assuming that I have privileges to run newgrp immiediately after login, wouldn't this be the same as changing my default primary GUID for all practical purposes?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

On Linux (not BusyBox), Solaris, NetBSD, OpenBSD: usermod -g group

The usermod command modifies the system account files to reflect the changes that are specified on the command line

-g, --gid GROUP

The group name or number of the users new initial login group. The group must exist. Any file from the users home directory owned by the previous primary group of the user will be owned by this new group.

The group ownership of files outside of the users home directory must be fixed manually.

On FreeBSD: pw usermod -g group

On BusyBox: addgroup -g user group

You won't be able to do this without root privileges.

share|improve this answer
    
+1 for nicely covering so many systems! Maybe you could also address the last (non-admin) part of the question? –  rozcietrzewiacz Oct 22 '11 at 17:36
2  
@rozcietrzewiacz As far as I know, adding newgrp to a startup script is the closest you can get without root privileges. If you were the admin of such a system and you wanted to let your users switch between a subset of groups without giving them root privileges, you could write a program to let them do it, and set the setuid bit on the program. –  Shawn J. Goff Oct 22 '11 at 17:45
    
I think so too. And this might be useful information to intrpc. –  rozcietrzewiacz Oct 22 '11 at 17:52

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.