Linux基础命令[19]-id

文章目录

    • [1. id 命令说明](#1. id 命令说明)
    • [2. id 命令语法](#2. id 命令语法)
    • [3. id 命令示例](#3. id 命令示例)
      • [3.1 不加参数](#3.1 不加参数)
      • [3.2 -u/-g/-G(用户、组、所属组)](#3.2 -u/-g/-G(用户、组、所属组))
      • [3.3 -gr/-Gr/-ur(有效ID)](#3.3 -gr/-Gr/-ur(有效ID))
    • [4. 总结](#4. 总结)

1. id 命令说明

id:显示真实有效的用户ID(UID)和组ID(GID),十分方便,不用再查找 /etc/groop(里面有全部用户的信息)。基本信息如下:

Usage: id [OPTION]... [USERNAME]
Print user and group information for the specified USERNAME,
or (when USERNAME omitted) for the current user.

  -a              ignore, for compatibility with other versions
  -Z, --context   print only the security context of the current user
  -g, --group     print only the effective group ID
  -G, --groups    print all group IDs
  -n, --name      print a name instead of a number, for -ugG
  -r, --real      print the real ID instead of the effective ID, with -ugG
  -u, --user      print only the effective user ID
      --help     display this help and exit
      --version  output version information and exit

Without any OPTION, print some useful set of identified information.

Report id bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'id invocation'

参数如下:

选项 作用
-a 忽略该命令,仅为了与其他版本兼容
-Z 仅显示当前用户的安全内容
-g 显示用户所属群组的ID
-G 显示用户所属所有群组,包括附加群组的ID
-n 显示用户,所属群组或附加群组的名称
-r 显示实际的ID
-u 显示当前用户ID

2. id 命令语法

shell 复制代码
id [OPTION]... [USERNAME]

3. id 命令示例

3.1 不加参数

不加用户名时,显示当前用户的信息,包括 uid gid groups

shell 复制代码
id

加用户名时,显示的是该用户的 uid gid groups

shell 复制代码
id admin

3.2 -u/-g/-G(用户、组、所属组)

这三个参数配合 -n 使用时,会显示名称,也可以指定用户

shell 复制代码
id -u
shell 复制代码
id -un
shell 复制代码
id -un admin

3.3 -gr/-Gr/-ur(有效ID)

[root ~]$ id -gr
1101
[root ~]$ id -Gr
1101
[root ~]$ id -ur
1101
[root ~]$ id -ur admin
200
[root ~]$ id -Gr admin
200 10
[root ~]$ id -gr admin
200

4. 总结

id:用于显示当前或指定用户的 UID GID。

相关推荐
涛ing28 分钟前
32. C 语言 安全函数( _s 尾缀)
linux·c语言·c++·vscode·算法·安全·vim
__雨夜星辰__30 分钟前
Linux 学习笔记__Day2
linux·服务器·笔记·学习·centos 7
大耳朵土土垚30 分钟前
【Linux】日志设计模式与实现
linux·运维·设计模式
学问小小谢33 分钟前
第26节课:内容安全策略(CSP)—构建安全网页的防御盾
运维·服务器·前端·网络·学习·安全
yaoxin5211232 小时前
第十二章 I 开头的术语
运维·服务器
ProgramHan2 小时前
1992-2025年中国计算机发展状况:服务器、电脑端与移动端的演进
运维·服务器·电脑
马立杰5 小时前
H3CNE-33-BGP
运维·网络·h3cne
云空6 小时前
《DeepSeek 网页/API 性能异常(DeepSeek Web/API Degraded Performance):网络安全日志》
运维·人工智能·web安全·网络安全·开源·网络攻击模型·安全威胁分析
深度Linux6 小时前
Linux网络编程中的零拷贝:提升性能的秘密武器
linux·linux内核·零拷贝技术
没有名字的小羊7 小时前
Cyber Security 101-Build Your Cyber Security Career-Security Principles(安全原则)
运维·网络·安全