You are not logged in.
Is there a command line command that will simply display the user groups that a user belongs to?
Is there a command line command that will simply add a supplied group name to the list of groups a user belongs to?
Finally, is there a command line command that will list all the defined groups in the system?
Thanks!
Cast off the Microsoft shackles Jan 2005
Offline
Is there a command line command that will simply display the user groups that a user belongs to?
# groups <user>
Is there a command line command that will simply add a supplied group name to the list of groups a user belongs to?
# gpasswd -a <user> <group>
Finally, is there a command line command that will list all the defined groups in the system?
Take a look at the first field of each line /etc/group file. There's probably a simpler way to do it, but:
# awk -F ":" '{print $1;}' </etc/group | sort
Hope that helps!
~Peter~
Offline
codergeek42, thanks! One question. If I do a man page lookup on gpasswd, it tells me that this command changes the password for a group. Further, there is no "-a" option listed. Did you REALLY mean "gpasswd"?
Cast off the Microsoft shackles Jan 2005
Offline
1. $ groups
2. $ gpasswd -a user group
3. Don't know about the specific command but
$ cat /etc/group will display all the available groups. Don't try to manage groups by editing /etc/group. Instead, use the gpasswd utility.
Offline
he meant what he said
Frumpus ♥ addict
[mu'.krum.pus], [frum.pus]
Offline
codergeek42 beat me!
It's really gpasswd and the -a option is listed.
$ man gpasswd
Perhaps you were looking at another man page or missed it.
Offline
OK, you caught me. I am reading this on a SuSE 9.3 machine right now, and when I do "man gpasswd" I get a manpage for a command that changes the password for a group, and only has a "-r" option. I'll try this out again when I boot my Arch system and hopefully, all will be well. Thanks for the help, and thanks especially for that awk sequence. Works like a champ, but I would have never been able to think it up. Never spent much time awk.
Cast off the Microsoft shackles Jan 2005
Offline
~Peter~
Offline
There's probably a simpler way to do it, but:
# awk -F ":" '{print $1;}' </etc/group | sort
Hope that helps!
Little bit simpler:
cat /etc/group | cut -d: -f1
Offline
I knew there had to be a nicer way of doing that! Thanks, phrakture.
(By the way, `cat foo | cmd` in Bash can usually be replaced by `cmd < foo` just FYI )
~Peter~
Offline
Is there a command line command that will simply add a supplied group name to the list of groups a user belongs to?
usermod -a -G <group> <user>
Offline
Excellent, thanks. This seems more intuitively obvious than the gpasswd command. Thanks again.
Cast off the Microsoft shackles Jan 2005
Offline