Get User ID or UID in Ubuntu
USER ID or UID as known as user identifier identify a user by a value. UID and GID along with the access control criteria ,is used to determine which system resources you can access.
Get USERID or UID using command ID
id
As you can see the screenshot above, id
command shows my UID is 1000, GID is also 1000.
Print UID only using command ID
j@ubuntu:~$ id -u
1000
Using option -u
, command id
print your user id only.
Get userid of specific user
id USER
Without a username ,command id
prints current user’s information. So if you want to get other user’s USERID , you can specify that username.
For example ,below command shows the USERID and GROUPID of root
j@ubuntu:~$ id root
uid=0(root) gid=0(root) groups=0(root)
More examples
Print user id only for specific user
id -u USER
Print group ID only for specific user
id -g user
Get user ID using getent
The getent command displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf.
getent passwd USER
For example
j@ubuntu:~$ getent passwd j
j:x:1000:1000:Ubuntu01,,,:/home/j:/bin/bash
You can see getent
also shows more information about user j
Ubuntu01
: user’s description/home/j
: location of home directory/bin/bash
: default shell