User ID in Linux

To print user ID in Linux, we can use id command.

id

Example 1 – User Id of root user

In this example, we get the user ID of root user.

Linux - Get User ID

We are currently logged in as root.

root@tutorialkart#

To get the user ID of root user, execute the id command.

root@tutorialkart# id
uid=0(root) gid=0(root) groups=0(root)

uid is our user ID. id prints group id gid and groups information as well, along with the user ID.

ADVERTISEMENT

Example 2 – User ID of another user

In this example, we get the user ID of user prasanna (who is logged in right now).

Linux - Get user id

Now we have logged in as another user, say prasanna.

prasanna@tutorialkart#

Let us get the user ID of this user using id command.

prasanna@tutorialkart# id
uid=1000(prasanna) gid=1000(prasanna) groups=1000(prasanna) ,4(adm) ,24(cdrom) ,27(sudo) ,30(dip) ,46(plugdev) ,120(lpadmin) ,131(lxd) ,132(sambashare)

Conclusion

In this Linux Tutorial, we learned how to get the user ID of current user using id command.