Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'id' Command In Linux

2023-05-22 - By Robert Elder

     I use the 'id' command to list all of the id values that represent users and groups on my system.  By default, the 'id' command will show the ID information associated with the current user and all of the groups that the current user belongs to:

id
uid=1000(robert) gid=1000(robert) groups=1000(robert),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare),1001(tomcat)

Origin Of Group And User Ids

     These ID values can also be found in the file located at '/etc/passwd':

cat /etc/passwd
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
robert:x:1000:1000:robert,,,:/home/robert:/bin/bash
tomcat:x:1001:1001::/opt/tomcat:/bin/false
...

     and the group 'id's can be found in the '/etc/group' file:

cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,robert
tty:x:5:syslog
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
...

Show ID Information For A Specific User

     You can also specify a user to the 'id' command to see information for only that user:

id postgres
uid=126(postgres) gid=133(postgres) groups=133(postgres),113(ssl-cert)

Effective User ID Using '-u' Flag

     The '-u' flag restricts the output to show only the effective user ID:

id -u
1000

Effective Group ID Using '-g' Flag

     The '-g' flag shows the effective group ID:

id -g
1000

Group ID Memberships Using '-G' Flag

     and the '-G' flag shows the IDs of groups that the user belongs to:

id -G
1000 4 20 24 27 30 46 120 131 132 1001

Effective User ID Versus Real User ID

     If you make a copy of the 'id' command executable:

cp /usr/bin/id ./id-copy

     and then enable the setuid bit, while also changing the file ownership:

sudo chown postgres:postgres id-copy
sudo chmod u+s id-copy

     you'll be able to observe a difference between the effect of user ID and the real user ID:

./id-copy -u
126
./id-copy -ru
1000

     And that's why the 'id' command is my favourite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use