I have a problem on a server I manage. An account (specifically, my account) does not seem to have the correct groups. I think the problem is most easily demonstrated by looking at the following command sequence:

Last login: sometime from somewhere
user.x@srv:~$ groups
user.x@srv:~$ groups user.x
user.x : user.x grp1 grp2
user.x@srv:~$ su - user.x
user.x@srv:~$ groups
user.x grp1 grp2
user.x@srv:~$ exit
user.x@srv:~$ groups

So the problem is that the groups for user.x are incorrectly reported after logging in (through SSH). If logging in is simulated again (su -) or the username is supplied with the groups or id command it works fine.

The incorrect groups cause all sorts of problems, like not being able to sudo. How can I fix this?

Further information that might be relevant:

  • The server is a NIS client which synchronises every 15 minutes
  • The problem is rare, but not unique, at the moment 2 users have acquired it in the last half-year
  • The problem seems to only happen to users that SSH into the machine often
  • What is the situation when you log in and then run /bin/bash --login instead of su -? – rozcietrzewiacz Aug 29 '11 at 15:36
  • @rozcietrzewiacz Then the group information is invalid too. The same holds true for /bin/dash -l – dtech Aug 29 '11 at 16:23
  • This looks like some broken configuration then, probably something in /etc/profile - see my answer. – rozcietrzewiacz Aug 29 '11 at 16:34

The problem was that the group information was first pulled from nis and then from the local copies of the nis (made by ypserv)

The solution was changing /etc/nsswitch.conf from

group: compat


group: files nis compat
| improve this answer | |

Group permissions are set at the time the shell is created. The very first shell where groups output only shows user.x, was that shell created before adding the other groups? If so simply log out and log in again.

| improve this answer | |
  • The groups were created long before this particular SSH session was started. The commands are literately run after logging in. – dtech Aug 29 '11 at 16:22

It looks like a problem with the user shells' configurations. Check how the shells are defined in /etc/passwd and inspect the /etc/profile, users' login scripts (like .bashrc, .bash_login, .profile etc.) for any errors. If you don't find anything that would fix it, backup those files and restore default ones. Possibly re-install the shell(s).

| improve this answer | |

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.