- Linux / Unix id Command Examples
- Purpose
- id command syntax
- Linux / Unix id command examples
- Display your own UID and GID
- How do I find a specific user’s UID?
- How do I find a specific user’s GID?
- How do I see the UID and all groups associated with a user name?
- Find out all the groups a user belongs to…
- Display a name instead of a UID/GID
- How do I display real ID instead of the effective ID for specified user?
- UNIX / Linux Find File Owner Name
- How do I find out owner / group name for a file?
- ls -l file mode (permissions)
- Как узнать id пользователя Linux
- Как узнать id пользователя в Linux
- Выводы
- 📑 Команда id — найти UID пользователя или GID
- синтаксис команды id
- Показать свой собственный UID и GID
- Как найти UID конкретного пользователя?
- Как найти GID конкретного пользователя?
- Как увидеть UID и все группы, связанные с именем пользователя?
- Как узнать все группы, к которым принадлежит пользователь…
- Отображать имя вместо UID / GID
- Параметры команды 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
|
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:
Источник
UNIX / Linux Find File Owner Name
Q. How do I find out the name of file / directory owner under UNIX / Linux operating systems?
A. You can use ls -l command (list information about the FILEs) to find our the file / directory owner and group names.
The -l option is known as long format which displays Unix / Linux / BSD file types, permissions, number of hard links, owner, group, size, date, and filename. In some environments and UNIX versions / Linux distributions, providing the option –color (for GNU ls) or -G (FreeBSD ls) causes ls to highlight different types of files with different colors.
(Fig. 01: Linux file colors)
(Fig. 02: Understanding Linux / UNIX file colors code [ image credit wikipedia] )
How do I find out owner / group name for a file?
Type the ls -l command at a shell prompt:
$ ls -l filename
Sample output:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
- -rw-r–r– : file mode
- 1 – number of links
- vivek – Owner name (if user name is not a known user, the numeric user id displayed)
- admin – Group name (if group name is not a known group, the numeric group id displayed)
- 2558 – number of bytes in the file (file size)
- Jan 8 07:41 – abbreviated month, day-of-month file was
last modified, hour file last modified, minute file last modified - filename – File name / pathname
ls -l file mode (permissions)
Quoting from the unix ls command man page – the file mode printed under the -l option consists of the entry type and the permissions. The entry type character describes the type of file, as follows:
– | Regular file. |
b | Block special file. |
c | Character special file. |
d | Directory. |
l | Symbolic link. |
p | FIFO. |
s | Socket. |
w | Whiteout. |
The next three fields are three characters each: owner permissions, group permissions, and other permissions. Each field has three character positions:
- If r, the file is readable; if -, it is not readable.
- If w, the file is writable; if -, it is not writable.
- The first of the following that applies:
- S : If in the owner permissions, the file is not executable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set.
- s : If in the owner permissions, the file is executable and set-user-ID mode is set. If in the group permissions, the file is executable and set group-ID mode is set.
- x : The file is executable or the directory is searchable.
- – : The file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky.
- T : The sticky bit is set (mode 1000), but not execute or search permission.
- t : The sticky bit is set (mode 1000), and is search able or executable.
See ls command man page for more information:
$ man ls
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
Как узнать id пользователя Linux
Иногда возникает необходимость узнать id пользователя Linux. Это может понадобиться, если вы хотите вручную добавить группу для пользователя или вам нужно выполнить другие операции с файлами /etc/passwd или /etc/shadow.
В этой небольшой заметке мы поговорим о том, как посмотреть id пользователя с помощью различных команд в Linux.
Как узнать id пользователя в Linux
Самый простой способ посмотреть идентификатор текущего пользователя — использовать команду id, она выводит не только сам UID, но и идентификатор группы пользователя, а также основные группы этого пользователя:
Первым выводится именно id пользовтеля. Если вам нужно узнать информацию о другом пользователе, вы можете передать его имя в параметры утилиты:
Когда необходимо вывести только id пользователя:
id -u имя_пользовтеля
Если вам надо узнать только id группы определенного пользователя, то используйте опцию -g:
id -g имя_пользователя
Есть ещё несколько способов посмотреть id. Например, для текущего пользователя его можно найти в переменной окружения UID:
Ещё один вариант — утилита getent:
getent passwd имя_пользователя
Или смотрим содержимое файла /etc/passwd с помощью команды grep:
grep имя_пользователя /etc/passwd
Здесь первый цифровой параметр — это сам id, а второй, который расположен за двоеточием, — это GID.
Выводы
В этой небольшой статье мы рассмотрели, как узнать id пользователя Linux. Если у вас остались вопросы, спрашивайте в комментариях!
Источник
📑 Команда 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
Источник