Thursday, 26 September 2019

id command in Linux with examples

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

The Linux Professional Institute currently offers three different certification programs. The core certification program LPIC contains three different levels addressing distinct aspects of Linux system administration.

id command


id command in Linux is used to find out user and group names and numeric ID’s (UID or group ID) of the current user or any other user in the server. This command is useful to find out the following information as listed below:

◈ User name and real user id.
◈ Find out the specific Users UID.
◈ Show the UID and all groups associated with a user.
◈ List out all the groups a user belongs to.
◈ Display security context of the current user.

Synopsis:


id [OPTION]… [USER]

Options:


◈ -g : Print only the effective group id.
◈ -G : Print all Group ID’s.
◈ -n : Prints name instead of number.
◈ -r : Prints real ID instead of numbers.
◈ -u : Prints only the effective user ID.
◈ –help : Display help messages and exit.
◈ –version : Display the version information and exit.

Note: Without any OPTION it prints every set of identified information i.e. numeric ID’s.

Examples:


◈ To print your own id without any Options:

id

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

The output shows the ID of current user UID and GID.

◈ To find a specific users id: Now assume that we have a user named master, to find his UID we will use the command:

id -u master

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

◈ To find a specific users GID: Again assuming to find GID of master, we will use the command:

id -g master

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

◈ To find out UID and all groups associated with a username: In this case we will use the user “master” to find UID and all groups associated with it, use command:

id master

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

◈ To find out all the groups a user belongs to: Displaying the UID and all groups a user “master” belongs to:

id -G master

◈ To display a name instead of numbers: By default the id command shows us the UDI and GID in numbers which a user may not understand, with use of -n option with -u, -g and -G, use command(s)

id -ng master 
or
id -nu master
or
id -nG master

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

◈ To display real id instead of effective id: To show the real id with the use of -r option with -g, -u and -G, use command(s):

id -r -g master
id -r -u master
id -r -G master

LPI Study Materials, LPI Guides, LPI Tutorials and Materials, LPI Online Exam

Related Posts

0 comments:

Post a Comment