-nu id linux
2011-11-17 11:02:55 ysdaniel 阅读数 5716
id --help
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


[root@localhost proc]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[root@localhost proc]# id -un
root

2013-02-28 02:46:55 zuoanlove 阅读数 221

转载自:http://blog.csdn.net/ysdaniel/article/details/6980917

id --help
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


[root@localhost proc]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[root@localhost proc]# id -un
root


Linux id
2018-11-08 16:40:39 JxufeCarol 阅读数 38

linux id 命令详解

功能说明:显示用户的ID,以及所属群组的ID。

语法:id [-gGnru][–help][–version][用户名称]

补充说明:id会显示用户以及所属群组的实际与有效ID。若两个ID相同,则仅显示实际ID。若仅指定用户名称,则显示目前用户的ID。

参  数:
  -g或–group  显示用户所属群组的ID
  -G或–groups  显示用户所属附加群组的ID
  -n或–name  显示用户,所属群组或附加群组的名称
  -r或–real  显示实际ID
  -u或–user  显示用户ID
  -help  显示帮助
  -version  显示版本信息

Linux ID
2015-06-12 21:41:56 kzjay 阅读数 747

原文:http://0pointer.de/blog/projects/ids.html

When programming software that cooperates with software running on behalf ofother users, other sessions or other computers it is often necessary to work withunique identifiers. These can be bound to various hardware and software objectsas well as lifetimes. Often, when people look for such an ID to use they pickthe wrong one because semantics and lifetime or the IDs are not clear. Here's alittle incomprehensive list of IDs accessible on Linux and how you should orshould not use them.

Hardware IDs

  1. /sys/class/dmi/id/product_uuid: The main board product UUID, asset by the board manufacturer and encoded in the BIOS DMI information. It maybe used to identify a mainboard and only the mainboard. It changes when theuser replaces the main board. Also, often enough BIOS manufacturers write bogusserials into it. In addition, it is x86-specific. Access for unprivileged usersis forbidden. Hence it is of little general use.
  2. CPUID/EAX=3 CPU serial number: A CPU UUID, as set by theCPU manufacturer and encoded on the CPU chip. It may be used to identify a CPUand only a CPU. It changes when the user replaces the CPU. Also, most modernCPUs don't implement this feature anymore, and older computers tend to disablethis option by default, controllable via a BIOS Setup option. In addition, itis x86-specific. Hence this too is of little general use.
  3. /sys/class/net/*/address: One or more network MAC addresses, asset by the network adapter manufacturer and encoded on some network cardEEPROM. It changes when the user replaces the network card. Since network cardsare optional and there may be more than one the availability if this ID is notguaranteed and you might have more than one to choose from. On virtual machinesthe MAC addresses tend to be random. This too is hence of little general use.
  4. /sys/bus/usb/devices/*/serial: Serial numbers of various USBdevices, as encoded in the USB device EEPROM. Most devices don't have a serialnumber set, and if they have it is often bogus. If the user replaces his USBhardware or plugs it into another machine these IDs may change or appear inother machines. This hence too is of little use.

There are various other hardware IDs available, many of which you maydiscover via the ID_SERIAL udev property of various devices, such hard disksand similar. They all have in common that they are bound to specific(replacable) hardware, not universally available, often filled with bogus dataand random in virtualized environments. Or in other words: don't use them, don'trely on them for identification, unless you really know what you are doing andin general they do not guarantee what you might hope they guarantee.

Software IDs

  1. /proc/sys/kernel/random/boot_id: A random ID that is regeneratedon each boot. As such it can be used to identify the local machine's currentboot. It's universally available on any recent Linux kernel. It's a good andsafe choice if you need to identify a specific boot on a specific bootedkernel.
  2. gethostname(), /proc/sys/kernel/hostname: A non-random IDconfigured by the administrator to identify a machine in the network. Oftenthis is not set at all or is set to some default value such aslocalhost and not even unique in the local network. In addition itmight change during runtime, for example because it changes based on updatedDHCP information. As such it is almost entirely useless for anything butpresentation to the user. It has very weak semantics and relies on correctconfiguration by the administrator. Don't use this to identify machines in adistributed environment. It won't work unless centrally administered, whichmakes it useless in a globalized, mobile world. It has no place inautomatically generated filenames that shall be bound to specific hosts. Justdon't use it, please. It's really not what many people think it is.gethostname() is standardized in POSIX and hence portable to otherUnixes.
  3. IP Addresses returned by SIOCGIFCONF or the respective Netlink APIs: Thesetend to be dynamically assigned and often enough only valid on local networksor even only the local links (i.e. 192.168.x.x style addresses, or even169.254.x.x/IPv4LL). Unfortunately they hence have little use outside ofnetworking.
  4. gethostid(): Returns a supposedly unique 32-bit identifier for thecurrent machine. The semantics of this is not clear. On most machines thissimply returns a value based on a local IPv4 address. On others it isadministrator controlled via the /etc/hostid file. Since the semanticsof this ID are not clear and most often is just a value based on the IP address it isalmost always the wrong choice to use. On top of that 32bit are notparticularly a lot. On the other hand this is standardized in POSIX and henceportable to other Unixes. It's probably best to ignore this value and if peopledon't want to ignore it they should probably symlink /etc/hostid to/var/lib/dbus/machine-id or something similar.
  5. /var/lib/dbus/machine-id: An ID identifying a specific Linux/Unixinstallation. It does not change if hardware is replaced. It is not unreliablein virtualized environments. This value has clear semantics and is consideredpart of the D-Bus API. It is supposedly globally unique and portable to allsystems that have D-Bus. On Linux, it is universally available, given thatalmost all non-embedded and even a fair share of the embedded machines shipD-Bus now. This is the recommended way to identify a machine, possibly with afallback to the host name to cover systems that still lack D-Bus. If yourapplication links against libdbus, you may access this ID withdbus_get_local_machine_id(), if not you can read it directly from the file system.
  6. /proc/self/sessionid: An ID identifying a specific Linux loginsession. This ID is maintained by the kernel and part of the auditing logic. Itis uniquely assigned to each login session during a specific system boot,shared by each process of a session, even across su/sudo and cannot be changedby userspace. Unfortunately some distributions have so far failed to set thingsup properly for this to work (Hey, you, Ubuntu!), and this ID is always(uint32_t) -1 for them. But there's hope they get this fixedeventually. Nonetheless it is a good choice for a unique session identifier onthe local machine and for the current boot. To make this ID globally unique itis best combined with /proc/sys/kernel/random/boot_id.
  7. getuid(): An ID identifying a specific Unix/Linux user. This ID isusually automatically assigned when a user is created. It is not unique acrossmachines and may be reassigned to a different user if the original user wasdeleted. As such it should be used only locally and with the limited validityin time in mind. To make this ID globally unique it is not sufficient tocombine it with /var/lib/dbus/machine-id, because the same ID might beused for a different user that is created later with the same UID. Nonethelessthis combination is often good enough. It is available on all POSIX systems.
  8. ID_FS_UUID: an ID that identifies a specific file system in theudev tree. It is not always clear how these serials are generated but thistends to be available on almost all modern disk file systems. It is notavailable for NFS mounts or virtual file systems. Nonetheless this is often agood way to identify a file system, and in the case of the root directory evenan installation. However due to the weakly defined generation semantics theD-Bus machine ID is generally preferrable.

Generating IDs

Linux offers a kernel interface to generate UUIDs on demand, by reading from/proc/sys/kernel/random/uuid. This is a very simple interface togenerate UUIDs. That said, the logic behind UUIDs is unnecessarily complex andoften it is a better choice to simply read 16 bytes or so from/dev/urandom.

Summary

And the gist of it all: Use /var/lib/dbus/machine-id! Use/proc/self/sessionid! Use /proc/sys/kernel/random/boot_id!Use getuid()! Use /dev/urandom! And forget about therest, in particular the host name, or the hardware IDs such as DMI. And keep inmind that you may combine the aforementioned IDs in various ways to getdifferent semantics and validity constraints.


2017-07-30 14:34:03 sdd220 阅读数 1094

Linux进程有两个ID,一个就是用户ID,为每个用户的唯一标识符;另一个是组ID,为用户组的唯一标识符

UID:UID的值为0时,表示系统管理员;(1-99)为系统预设账号;(100-499)保留给一些服务使用;(500-65535)给一般使用者使用

可在终端输入cat /etc/passwd | grep 你的用户名指令查询UID和GID

这里写图片描述

user用户的UID和GID分别是1000:1000

setuid, setgid 可以来改变这种设置.
  setuid: 设置使文件在执行阶段具有文件所有者的权限。典型的文件是 /usr/bin/passwd. 如果一般用户执行该文件, 则在执行过程中, 该文件可以获得root权限, 从而可以更改用户的密码。
  setgid: 该权限只对目录有效,目录被设置该位后, 任何用户在此目录下创建的文件都具有和该目录所属的组相同的组。

linux之id和passwd

阅读数 364

linux id命令

阅读数 993

linux id 命令详解

阅读数 5

Linux 线程ID

阅读数 918

Linux id 命令

阅读数 389

没有更多推荐了,返回首页