Linux 小知识 丨id sudo 命令

620 阅读2分钟

这是我参与11月更文挑战的第8天,活动详情查看:2021最后一次更文挑战

Linux 小知识 丨id sudo 命令

id 命令

查看当前用户的详细信息(用户id, 群组id, 所属组)

id [-g][--help][--version][用户名称]

[root@VM-8-10-centos ~]# id root
uid=0(root) gid=0(root) groups=0(root)

[root@VM-8-10-centos ~]# id user1
uid=1002(user1) gid=1002(user1) groups=1002(user1),1004(devgroup) 

常用参数选项

  • -g, --group 显示用户所属群组的ID

  • -G, --groups 显示用户所属附加群组的ID

  • -n, --name 显示用户,所属群组或附加群组的名称

  • -r, --real 显示实际ID

  • -u, --user 显示用户ID

  • --help 显示帮助

  • --version 显示版本信息

sudo 命令

提高普通用户的操作权限

sudu [参数选项]
[root@VM-8-10-centos ~]# sudo --help
Options:
  -A, --askpass                 use a helper program for password prompting
  -b, --background              run command in the background
  -B, --bell                    ring bell when prompting
  -C, --close-from=num          close all file descriptors >= num
  -E, --preserve-env            preserve user environment when running command
      --preserve-env=list       preserve specific environment variables
  -e, --edit                    edit files instead of running a command
  -g, --group=group             run command as the specified group name or ID
  -H, --set-home                # 将环境变量中的HOME指定为要变更身份的使用者HOME目录
  -h, --help                    display help message and exit
  -h, --host=host               # 会显示版本编号和指令的使用方式说明
  -i, --login                   run login shell as the target user; a command may also be
                                specified
  -K, --remove-timestamp        remove timestamp file completely
  -k, --reset-timestamp         # 下一次执行sudo时询问密码
  -l, --list                    list user's privileges or check a specific command; use
                                twice for longer format
  -n, --non-interactive         non-interactive mode, no prompts are used
  -P, --preserve-groups         preserve group vector instead of setting to target's
  -p, --prompt=prompt           use the specified password prompt
  -r, --role=role               create SELinux security context with specified role
  -S, --stdin                   read password from standard input
  -s, --shell                   # 执行环境变量中的SHELL所指定的shell或是 /etc/passwd里所指定的shell
  -t, --type=type               create SELinux security context with specified type
  -T, --command-timeout=timeout terminate command after the specified time limit
  -U, --other-user=user         in list mode, display privileges for user
  -u, --user=user               run command (or edit file) as specified user name or ID
  -V, --version                 # 显示版本号
  -v, --validate                # 超出N分钟没有使用,要求再次输入密码(默认5分钟)
# sudo command 要以系统管理者身份(或以-u更改为其他人)执行的指令