8

Asked and answered many times, but I can't get it working!!!

(On CentOS) I have the user userA and I want to remove it from group sftponly.

#groups userA
userA : sftponly
#id -Gn userA
sftponly
#gpasswd -d userA sftponly
Removing user userA from group sftponly
gpasswd: unknown member userA

#tail /etc/group
userA:x:509:
sftponly:x:510:
#tail /etc/passwd
userA:x:509:510::/home/userA:/bin/bash/

so gpasswd not working. Also:

usermod -G fourpoints fourpoints 

No result.

I don't know really what to do, I'm not sure about editing /etc/group either...

3 Answers 3

19

Ran into the same issue. Was able to do the following to resolve this:

gpasswd -d user group

2
  • 3
    No idea why this answer has not been upvoted. It's best practice! May 21, 2015 at 20:25
  • 1
    As pointed out by @glasnhost, this does not work if the group you want to remove, is the users main group; on Centos 7 anyways. Switching the main group first, then running gpasswd no longer gives me errors like gpasswd: user 'userA' is not a member of 'sftponly'
    – PanPipes
    Jan 25, 2018 at 10:48
2

You cannot remove this user from that group given it's the only group that they're a member of. This is evident in the output being returned to you by the groups userA command:

$ groups userA
userA : sftponly

Also the id output:

$ id -Gn userA
sftponly

Look in the /etc/passwd file for this user, this is most probably their primary group. You'll have to either move them to another group (by changing their primary in /etc/passwd) or delete their account entirely.

1

I think it's necessary first to change the main group to the userA:

#usermod -g userA userA

and then the user can be removed from the group with gpasswd

1
  • 1
    This answer, plus @chris-olin allowed me to remove a user from a group that was their current default, without getting errors like: gpasswd: user 'userA' is not a member of 'sftponly'. This was on Centos 7.
    – PanPipes
    Jan 25, 2018 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .