You are not logged in.

#1 2006-01-13 19:24:11

mac57
Member
From: St. Somewhere
Registered: 2006-01-06
Posts: 302
Website

Command Line Cmds for User Management

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

#2 2006-01-13 19:34:21

codergeek42
Member
From: Anaheim, CA (USA)
Registered: 2005-06-03
Posts: 90
Website

Re: Command Line Cmds for User Management

mac57 wrote:

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. smile There's probably a simpler way to do it, but:

# awk -F ":" '{print $1;}' </etc/group | sort

Hope that helps!


~Peter~

Offline

#3 2006-01-13 19:38:29

mac57
Member
From: St. Somewhere
Registered: 2006-01-06
Posts: 302
Website

Re: Command Line Cmds for User Management

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

#4 2006-01-13 19:38:37

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: Command Line Cmds for User Management

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

#5 2006-01-13 19:39:23

Moo-Crumpus
Member
From: Hessen / Germany
Registered: 2003-12-01
Posts: 1,487

Re: Command Line Cmds for User Management

he meant what he said smile


Frumpus addict
[mu'.krum.pus], [frum.pus]

Offline

#6 2006-01-13 19:42:20

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: Command Line Cmds for User Management

codergeek42 beat me! smile
It's really gpasswd and the -a option is listed.
$ man gpasswd
Perhaps you were looking at another man page or missed it.

Offline

#7 2006-01-13 19:50:32

mac57
Member
From: St. Somewhere
Registered: 2006-01-06
Posts: 302
Website

Re: Command Line Cmds for User Management

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

#8 2006-01-13 20:25:14

codergeek42
Member
From: Anaheim, CA (USA)
Registered: 2005-06-03
Posts: 90
Website

Re: Command Line Cmds for User Management

smile


~Peter~

Offline

#9 2006-01-13 20:27:55

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Command Line Cmds for User Management

codergeek42 wrote:

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

#10 2006-01-13 21:46:01

codergeek42
Member
From: Anaheim, CA (USA)
Registered: 2005-06-03
Posts: 90
Website

Re: Command Line Cmds for User Management

I knew there had to be a nicer way of doing that! Thanks, phrakture. smile

(By the way, `cat foo | cmd` in Bash can usually be replaced by `cmd < foo` just FYI wink)


~Peter~

Offline

#11 2006-01-17 14:29:06

loserMcloser
Member
From: Canada
Registered: 2004-12-15
Posts: 130

Re: Command Line Cmds for User Management

mac57 wrote:

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

#12 2006-01-20 03:15:05

mac57
Member
From: St. Somewhere
Registered: 2006-01-06
Posts: 302
Website

Re: Command Line Cmds for User Management

Excellent, thanks. This seems more intuitively obvious than the gpasswd command. Thanks again.


Cast off the Microsoft shackles Jan 2005

Offline

Board footer

Powered by FluxBB