LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-04-2008, 09:34 AM   #1
vitalstrike82
Member
 
Registered: Oct 2007
Location: Singapore
Distribution: OpenSuse, Slackware, Redhat
Posts: 318

Rep: Reputation: 40
Using the groups command


Greetings,
i'm a bit confused how this groups command is use.

Right now i logging in into my account. I type groups command.

It shows this list
Code:
chongming@linux:~$ groups
users floppy audio video cdrom
I like to ask if the display groups the groups which i'm already in? Because when i type in this command:

Code:
chongming@linux:~$ groups chongming
plugdev
The above shows only plugdev. I like to ask if whether i'm inside
users floppy audio video cdrom plugdev groups..

This is my /etc/group list:

Code:
chongming@linux:~$ cat /etc/group
root:x:0:root
bin:x:1:root,bin
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root,adm
lp:x:7:lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
floppy:x:11:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:
audio:x:17:root
video:x:18:root
cdrom:x:19:root
games:x:20:
slocate:x:21:
utmp:x:22:
smmsp:x:25:smmsp
tape:x:26:root
mysql:x:27:
rpc:x:32:
sshd:x:33:sshd
gdm:x:42:
shadow:x:43:
ftp:x:50:
apache:x:80:
messagebus:x:81:
haldaemon:x:82:
plugdev:x:83:root,chongming
power:x:84:
pop:x:90:pop
scanner:x:93:
nobody:x:98:nobody
nogroup:x:99:
users:x:100:
console:x:101:
Thanks
 
Old 11-04-2008, 09:58 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
The "groups" command should show what group memberships a user has.

A user is a member of groups when explicitly associated with them in /etc/groups (e.g. the plugdev line shows chongming is a member). Also users have a default group which is specified in /etc/passwd.

The first four fields of /etc/passwd should be something like:
user:x(or encrypted password if no shadow file):UID:GID:

Where:
user = the User (e.g. chongming)
UID = the User ID (number)
GID = the Group ID (number).

You can compare the GID number against the GID shown in 3rd field of /etc/group to determine which group that GID refers to.

The fact that "groups chongming" shows only plugdev would lead me to believe the GID for user "chongming" is 83. If so there is no reason to also have "chongming" in /etc/groups as it is redundant.

Typing "groups" without user name shows you the groups for the user that executed the command. Before executing the command type "whoami" (NOT "who am i") to verify you're the user you think you are. This shows your effective user rather than real user which might be different if you'd done an "su".
 
Old 11-04-2008, 10:07 AM   #3
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
The group command without a parameter is returning the current user's groups. When a username is passed as a parameter the /etc/group and the /etc/passwd files are looked at and group memberships are displayed from those. There may be a difference in the two as there may be console default groups in the /etc/login.defs file. This is accessed when logging into the console via login. Slackware is setup to automatically join certain groups - this is from the /etc/login.defs file :
Code:
#
# List of groups to add to the user's supplementary group set
# when logging in on the console (as determined by the CONSOLE
# setting).  Default is none.
#
# Use with caution - it is possible for users to gain permanent
# access to these groups, even when not logged in on the console.
# How to do it is left as an exercise for the reader...
#
# Most of these groups are self-explanatory, with the possible
# exception of "plugdev", which allows the use of plugable devices
# such as USB storage (flash memory sticks, most digital cameras,
# some media players, and other devices), many IEEE1394 (sometimes
# called "FireWire") devices, and more.  For plugdev devices, the
# use of HAL is required.  HAL also helps users interact with
# hardware in the other groups below (and other hardware) more
# easily as well, so it's a good idea to turn HAL on for any
# machine that will be used from the console.
#
# Note that users are added to these default groups only when
# logging into a shell with /bin/login, not when using a login
# manager such as kdm.  In that case, users who should have
# hardware access must be added to the appropriate groups
# when the user is added with adduser or useradd, or by editing
# /etc/group directly.
#
CONSOLE_GROUPS		floppy:audio:cdrom:video:plugdev
This explains the difference. It may also cause confusion when starting at runlevel 4 as the login process is different and the supplementary groups may not be joined. Because of this I'd recommend adding a user to the supplementary groups in the /etc/group file.

Last edited by bgeddy; 11-04-2008 at 10:14 AM. Reason: Further information
 
Old 11-05-2008, 01:43 AM   #4
vitalstrike82
Member
 
Registered: Oct 2007
Location: Singapore
Distribution: OpenSuse, Slackware, Redhat
Posts: 318

Original Poster
Rep: Reputation: 40
Hi,
thanks for the explaination.So that means the group which i'm in when i just type the command: groups, its shows users floppy audio video cdrom.

I assume these groups are set up by slackware in default. Am i right.

Next when i type groups chongming it show plugdev
I assume this happen because i manually add myself into this group.

Please correct me if i'm on the wrong track.

Thanks
 
Old 11-05-2008, 07:14 PM   #5
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Quote:
Originally Posted by vitalstrike82
Hi,
thanks for the explaination.So that means the group which i'm in when i just type the command: groups, its shows users floppy audio video cdrom.

I assume these groups are set up by slackware in default. Am i right.
No. You are transiently added to these groups in /etc/login.defs when in runlevel 3 (ie you start from a terminal and type startx to launch X). You should add yourself permanently using
Code:
# gpasswd -a chongming audio
# gpasswd -a chongming video
# gpasswd -a chongming floppy
# gpasswd -a chongming cdrom
# gpasswd -a chongming plugdev
You should probably change your initial group before you do that though -- you are currently have the plugdev group as your initial group. You *should* have the users group as your initial group. Try the following command BEFORE doing the gpasswd stuff above, and THEN do all of the gpasswd stuff above.
Code:
# usermod -g users chongming
 
Old 11-05-2008, 07:38 PM   #6
vitalstrike82
Member
 
Registered: Oct 2007
Location: Singapore
Distribution: OpenSuse, Slackware, Redhat
Posts: 318

Original Poster
Rep: Reputation: 40
oh i see the whole picture.

No wonder when i use usermod after restarting i wonder why i'm only in 1 group instead of 2.

So its my misunderstanding on my part.

Thanks for the help..


cheers
 
Old 11-06-2008, 07:53 AM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
No. You are transiently added to these groups in /etc/login.defs when in runlevel 3 (ie you start from a terminal and type startx to launch X). You should add yourself permanently using
Interesting - Is this slackware specific? I don't see anything about adding groups (other than setting minimum and maximum GID value) in /etc/login.defs on my RHEL and Fedora systems.

Also I would have suggested use of "usermod -G" instead of gpasswd but either would work.
 
Old 11-06-2008, 08:50 AM   #8
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Interesting - Is this slackware specific? I don't see anything about adding groups (other than setting minimum and maximum GID value) in /etc/login.defs on my RHEL and Fedora systems.
The supplementary groups are listed with CONSOLE_GROUPS as their label in /etc/login.defs and Debian Etch 4.0 has them set to floppy:audio:cdrom but commented out in the file.

Quote:
Also I would have suggested use of "usermod -G" instead of gpasswd but either would work.
A lot of people misread the useage of this command not realizing that the groups givien will override the previous settings i.e. it's not accumulative whereas gpasswd -a -g user group is. Slackware people tend to recommend the gpasswd way because of this.
 
Old 11-06-2008, 09:01 AM   #9
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
OK - No CONSOLE_GROUPS defined in RHEL/Fedora login.defs.

Also FYI - you can make usermod -G cummulative by adding the "-a" (append) flag.
 
Old 11-06-2008, 09:13 AM   #10
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Also FYI - you can make usermod -G cummulative by adding the "-a" (append) flag.
Not in Slackware.
 
Old 11-06-2008, 09:32 AM   #11
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Maybe version specific. You couldn't do it on RHEL3 either but you can on any Fedora 4 / RHEL 4 and higher.

My lone Debian box can't do it either but that version is a couple of years old.

Last edited by MensaWater; 11-06-2008 at 10:22 AM.
 
Old 11-06-2008, 09:42 AM   #12
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
My lone Debian box can't do it either but that version is a couple of years old.
I don't know if there's a connection with having the usermod -a flag and a lack of supplementary groups in login.defs. This had got me cycling through some VM's I rarely look at. Centos 5.2 server has no CONSOLE_GROUPS nor does PCLinux 2007 but Ubuntu 8 server does - possibly the Debian/RH connections there. Also makes me wish my additional memory had arrived as running multiple VM's soon slows stuff down ! Well - interesting stuff I suppose
 
Old 11-06-2008, 10:26 AM   #13
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
The Debian box has CONSOLE_GROUPS keyword but it is commented out and never had any groups assigned to it. But then again on that one I never got X running because it is an HP PA-RISC (HPPA) box. (Debian has a port for HPPA so I didn't have to roll my own.)

Not surprising about CentOS - It is built by compiling from RHEL source.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
command to list all groups radiodee1 Linux - Newbie 4 07-09-2007 04:33 PM
Command to see User Groups: what is it? TSynergy Linux - Newbie 3 11-17-2005 10:40 PM
How do I create accounts, groups and so on only using the command line? brynjarh Linux - Newbie 2 07-07-2004 01:42 PM
groups command not working.. samills70 Linux - Newbie 2 06-11-2004 05:22 AM
What command can list the userids in various user groups? davidas Linux - Newbie 1 04-16-2004 09:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration