Show user uid linux

Содержание
  1. 📑 Команда id — найти UID пользователя или GID
  2. синтаксис команды id
  3. Показать свой собственный UID и GID
  4. Как найти UID конкретного пользователя?
  5. Как найти GID конкретного пользователя?
  6. Как увидеть UID и все группы, связанные с именем пользователя?
  7. Как узнать все группы, к которым принадлежит пользователь…
  8. Отображать имя вместо UID / GID
  9. Параметры команды id
  10. Смотрите также
  11. Linux / Unix id Command Examples
  12. Purpose
  13. id command syntax
  14. Linux / Unix id command examples
  15. Display your own UID and GID
  16. How do I find a specific user’s UID?
  17. How do I find a specific user’s GID?
  18. How do I see the UID and all groups associated with a user name?
  19. Find out all the groups a user belongs to…
  20. Display a name instead of a UID/GID
  21. How do I display real ID instead of the effective ID for specified user?
  22. Everything Important You Need to Know About UID in Linux
  23. What is UID in Linux?
  24. How to find the UID of a user in Linux?
  25. How to change UID of a user in Linux?
  26. How does UID associate with different system resources? [for advanced users]
  27. UID and files
  28. UID and processes
  29. 6 Ways to check user information in Linux
  30. What kind of information is stored in the ‘/etc/passwd’ file
  31. 1) How to check user information using id command?
  32. 2) Checking user information using getent command
  33. 3) Checking user name and related information in Linux, using /etc/passwd file
  34. 4) How to check user information using finger Command
  35. 5) Checking user information in Linux, using lslogins command
  36. 6) How to check user & other information in Linux, using compgen command?
  37. Wrapping Up

📑 Команда id — найти UID пользователя или GID

Чтобы найти UID пользователя (ID пользователя) или GID (идентификатор группы) и другую информацию в Linux/Unix-подобных операционных системах, используйте команду id.

Эта команда полезна для поиска следующей информации:

  • Получить имя пользователя и реальный идентификатор пользователя
  • Найти UID конкретного пользователя
  • Перечислите все группы, к которым принадлежит пользователь
  • Показать UID и все группы, связанные с пользователем
  • Отображение контекста безопасности текущего пользователя
  • Эффективное имя пользователя Linux или Unix и эффективный идентификатор пользователя (UID)
  • Имя действующей группы пользователей Linux или Unix и идентификатор эффективной группы (GID)

Цель

Отображает системные идентификаторы указанного пользователя.

синтаксис команды id

По умолчанию команда id показывает имена пользователей и групп и числовые идентификаторы вызывающего процесса, то есть текущего пользователя, который запускает команду id на экране. Если имя пользователя или идентификатор пользователя ([UserNameHere]) указаны в командной строке, отображаются идентификаторы пользователя и группы этого пользователя.

Показать свой собственный UID и GID

Как найти UID конкретного пользователя?

В этом примере найдите UID пользователя vasia, введите:

Как найти GID конкретного пользователя?

В этом примере найдите GID пользователя vasia, запустите:

Как увидеть UID и все группы, связанные с именем пользователя?

В этом примере найдите UID и все группы, связанные с пользователем с именем «root», введите:

Как узнать все группы, к которым принадлежит пользователь…

В этом примере отобразите UID и все группы, связанные (вторичные группы) с пользователем с именем «vasia», запустите:

1000 20 12 61 79 80 81 98 33 100 204 398 399

Отображать имя вместо UID / GID

По умолчанию команда id отображает число для опций -G, -g и -u. Вы можете заставить команду id отображать имя UID или GID вместо номера для опций -G, -g и -u, передав опцию -n следующим образом:

Как отобразить реальный идентификатор вместо эффективного идентификатора для указанного пользователя?

Вы можете показать действительный идентификатор для параметров -g, -G и -u вместо эффективного идентификатора, передав опцию -r:

Параметры команды id

Опция Назначение OS
-g Показать только эффективный идентификатор группы ALL
-G Показать все идентификаторы группы ALL
-u Показать только эффективный идентификатор пользователя ALL
-n Показать имя вместо числа, для -u или -g ALL
-r Показать действительный идентификатор вместо действующего, с -u или -g ALL
-Z Показать только контекст безопасности текущего пользователя SELinux SELinux
-A Показать идентификатор пользователя аудита процесса и другие свойства аудита процесса Только Unix-like.

Смотрите также

man id — Страница руководства по команде id

Источник

Linux / Unix id Command Examples

I am a new Linux and Unix system user. How do I find out the user and groups names and numeric IDs of the current user or any users on my server? How can I display and effective IDs on the system using command line options? In Linux, how do I find a user’s UID or GID?

To find a user’s UID (user ID) or GID (group ID) and other information in Linux/Unix-like operating systems, use the id command.

id command details
Description Get user identity
Category N/A
Difficulty Easy
Root privileges No
Est. reading time 5m
Table of contents
  • » Syntax
  • » Examples
  • » Show your own UID and GID
  • » Display a user’s UID
  • » Display a user’s GID
  • » See groups associated with a user
  • » Display a name instead of a UID/GID
  • » Display real ID instead of the effective ID
  • » SELinux show security context
  • » Unix — Show process audit UID
  • » EUID and UID shell variables
  • » Determining root privileges in a script
  • » Options
  • » Related media
  • » See also

Purpose

Displays the system identifications of a specified user.

id command syntax

The basic syntax is:

id
id [UserNameHere] id [options] id [options] [UserNameHere]

By default id command shows the the user and group names and numeric IDs, of the calling process i.e. the current user who runs the id command on screen. If a login name or user ID ( [UserNameHere] ) given on command line, the user and group IDs of that user are displayed.

Linux / Unix id command examples

Let us see how to find a user’s UID or GID on Linux or Unix-like operating systems using 13 id command practical examples. First, open the Terminal application and then type:

Display your own UID and GID

Type the command:
id
Sample outputs:

Fig. 01: id command in action

How do I find a specific user’s UID?

In this example, find a vivek user’s UID, type:
id -u
id -u vivek
Sample outputs:

How do I find a specific user’s GID?

In this example, find a vivek user’s GID, run:
id -g
id -g vivek
Sample outputs:

How do I see the UID and all groups associated with a user name?

In this example, find the UID and all groups associated with a user called ‘root’, enter:
id
id root
Sample outputs:

Find out all the groups a user belongs to…

In this example, display the UID and all groups associated (secondary groups) with a user called ‘vivek’, run:
id -G
id -G vivek
Sample outputs

Display a name instead of a UID/GID

By default, id command displays number for the -G , -g and -u options. You can force id command to display the name of the UID or GID instead of the number for the -G , -g and -u options by passing the -n option as follows:
id -ng
id -nu
id -nG
id -nG vivek
Sample outputs:

How do I display real ID instead of the effective ID for specified user?

You can show the real ID for the -g , -G and -u options instead of the effective ID by passing the -r option:

Источник

Everything Important You Need to Know About UID in Linux

What is UID in Linux?

UID stands for user identifier. A UID is a number assigned to each Linux user. It is the user’s representation in the Linux kernel. The UID is used for identifying the user within the system and for determining which system resources the user can access. This is why the user ID should be unique.

You can find UID stored in the /etc/passwd file. This is the same file that can be used to list all the users in a Linux system.

Use a Linux command to view text file and you’ll see various information about the users present on your system.

The third field here represents the user ID or UID.

UID and GID in /etc/passwd File in Linux

Do note that in most Linux distributions, UID 1-500 are usually reserved for system users. In Ubuntu and Fedora, UID for new users start from 1000.

For example, if you use adduser or useradd command to create a new user, it will get the next available number after 1000 as its UID.

In Linux, UID 0 and GID 0 is reserved for the root user.

How to find the UID of a user in Linux?

You can always rely on the /etc/passwd file to get the UID of a user. That’s not the only way to get the UID information in Linux.

The id command in Linux will display the UID, GID and groups your current user belongs to:

You can also specify the user names with the id command to get the UID of any Linux user:

How to change UID of a user in Linux?

Suppose you had several users on your Linux system. You had to delete a user because he/she left the organization. Now you want its UID to be taken by another user already on the system.

You can change the UID by modifying the user using usermod command like this:

You need to have superuser privilege to execute the above command.

Do you remember the file permission and ownership concept in Linux? The ownership of a file is determined by the UID of the owner user.

When you update the UID of a user, what happens to the files owned by this user?While all the files in the home directory of user_2 will have their associated UID changed, you’ll have to manually update the associated UID of other files outside the home directory.

What you can do is manually update the ownership of the files associated with the old UID of the user_2.

How does UID associate with different system resources? [for advanced users]

UIDs are unique to one another and thus they can also be used to identify ownership of different system resources such as files and processes.

UID and files

I hope you are familiar with the file permission concept in Linux. When you’re creating a file, you’re the owner of this file. Now you can decide who gets to do what with this file. This is part of Linux’s DAC mechanism where each file is left at its owner’s discretion.

You can read a file’s ownership by using either ls or stat command. Let’s do it with the popular ls command and check the ownership of either the binary sleep or passwd .

As you can see, the file /usr/bin/sleep belongs to root:

Let’s force it to map the ownership with UID instead of username:

Here’s fun information. Your operating system doesn’t understand «usernames». Whenever a program needs to work with usernames or needs to print such, it refers to the /etc/passwd file to extract the information.

You don’t have to take my words for it. See it yourself with strace program which prints all the system calls made by a program.

What you are trying to see is whether ls command is trying to read the /etc/passwd file or not.

UID and processes

Processes have owners too, just like files. Only the owner (or the root user) of a process can send process signals to it. This is where the UID comes into play.

If a normal user tries to kill a process owned by another user, it will result in error:

Only the owner of the process or the root can do this.

A process must be regulated. Regulated as in you need to have a way to limit or know how much a process is allowed to do. This is determined by its UID(s).

There are three types of UIDs associated with a process.

  1. Real UID: Real UID is the UID that a process adopts from its parent. In easier terms, whoever starts a process, the UID of that user is the real UID of the process. This is helpful in identifying who a process really belongs to. This is essential especially when the effective UID is not the same as the real UID which I’m going to talk about next.
  2. Effective UID: This is what mostly determines what permissions a certain process really has. While a user can start the process, it can run with a different user’s available permissions. The command passwd is one example of this. This program edits the file /etc/shadow , which is root owned. Therefore, a normal user shouldn’t be able to run this command or change his/her password. Luckily, the binary runs with an effective UID of 0 (i.e. root), which enables it to have enough privilege to edit the /etc/shadow file. Real and effective UIDs are mostly the same except in the case of SUID bit enabled binaries.
  3. Saved UID: UID that’s available at a process’s disposal. This one is not normally used, but is still there in case the process knows it’s not going to perform any privileged work, so it can change its effective UID to something that’s unprivileged. This reduces the surface of an unintentional misbehavior.

That’s it. I hope you have a better idea about UID in Linux now. Don’t hesitate to ask your questions, if any.

As a pro Linux user, if you think I missed some important concept about UID, please let me know in the comment section.

Источник

6 Ways to check user information in Linux

Most of us use the id command , and some users filter the user information from the /etc/passwd file.

If you are a beginner for Linux operating systems and want to know more about the /etc/passwd file, please refer the following article.

In general, we use the above two commands to obtain user information. You may ask why to discuss this basic topic. People think there are no alternatives other other than these two commands, but we found that there are other ways to gather user information. Hence, we have created this article to guide you.

In this tutorial, we will discuss all these methods in detail. This is one of the basic commands that help the administrator to find information about a user in Linux.

Remember that everything is stored in a file on Linux, so be careful when handling the configuration file.

We have added several tweaks in this tutorial to collect user information with different aspect.

The following articles may help you to learn more about user management in Linux.

What kind of information is stored in the ‘/etc/passwd’ file

When creating users on Linux the user details are stored in the “/etc/passwd” file.

Each user information in this file is a single line with seven fields and the actual password is stored in the /etc/shadow file.

User information can be queried using these six methods:

  • id : Print user and group information for the specified username.
  • getent : Get entries from Name Service Switch libraries.
  • /etc/passwd file : The /etc/passwd file contain each/every user details as a single line with seven fields.
  • finger : User information lookup program
  • lslogins : lslogins display information about known users in the system
  • compgen : compgen is bash built-in command and it will show all available commands for the user.

1) How to check user information using id command?

The id command stands for identity. It prints real and effective user and group IDs. You can use the id command to print user and group information for the specified user, or for the current user.

Run id command without any username to print the current user information on your terminal.

To collect information on a specific user, use the id command followed by the specific username as shown below:

Details of the above output.

  • uid=500(daygeek): It shows the user ID & name
  • gid=500(daygeek): It displays the user’s primary group ID & name
  • groups=500(daygeek),10(wheel): It displays the user’s secondary groups ID & name

If you want to print multiple user information simultaneously using the id command, use the following small shell script. This script stores the list of users who have a home directory on the system in the variable.

To achieve this, write the following simple bash scripts.

Set an executable permission to “user-info.sh” file.

Finally run the script to get results:

2) Checking user information using getent command

The getent command displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf. The getent command displays user information such as the /etc/passwd file, which displays each user information on a separate line with seven fields.

The seven fields are described below in detail:

  • Username (magesh): Username of created user. Characters length should be between 1 to 32.
  • Password (x): It indicates that encrypted password is stored at /etc/shadow file.
  • User ID (UID-502): It indicates the user ID (UID) each user should be contain unique UID. UID (0-Zero) is reserved for root, UID (1-99) reserved for system users and UID (100-999) reserved for system accounts/groups
  • Group ID (GID-503): It indicates the group ID (GID) each group should be contain unique GID is stored at /etc/group file.
  • User ID Info (2g Admin — Magesh M): It indicates the command field. This field can be used to describe the user information.
  • Home Directory (/home/magesh): It indicates the user home directory.
  • shell (/bin/bash): It indicates the user’s bash shell.

If you want to display only the usernames in the getent command output, use the below format:

If you just want to display users that have home directory on system, use the below format:

Use the following format to add a UID to the getent command output:

The /etc/passwd is a text file containing every user information that is required to log in to the Linux system.

It holds useful information about users such as username, password, user ID, group ID, user ID information, home directory and shell. Each user profile in the “/etc/passwd” file is a single seperate lines with seven fields as described earlier in section #2.

If you only want to display usernames from the /etc/passwd file, use the below format:

If you only want to display users that have home directory on system, use the below format:

Use the following format to add a UID to the following command output:

If you only want to display users that have UID greater than 500 on the system, use the below format:

4) How to check user information using finger Command

The finger command displays information about the system users. It displays the user’s real name, tty name, idle time, login time, home directory and shell name.

Details of the above output.

  • Login: User’s login name
  • Name: Additional/Other information about the user
  • Directory: User home directory information
  • Shell: User’s shell information
  • LAST-LOGIN: Date of last login and other information

5) Checking user information in Linux, using lslogins command

It displays information about known users in the system. By default it will list information about all the users in the system.

The lslogins utility is inspired by the logins utility, which first appeared in FreeBSD 4.10.

Details of the above output.

  • UID: User id
  • USER: Name of the user
  • PWD-LOCK: password defined, but locked
  • PWD-DENY: login by password disabled
  • LAST-LOGIN: Date of last login
  • GECOS: Other information about the user

6) How to check user & other information in Linux, using compgen command?

The compgen is a bash built-in command and it will show all available commands, aliases, and functions for you as shown below:

Wrapping Up

In this guide, you learned several ways to find user information in Linux.

Please share this to your friends if it is helpful to you.

Источник

Читайте также:  Via hd audio windows 10 asrock
Оцените статью