有人可以解释 getent passwd 命令的输出吗?

jug*_*108 9 users user-management

mymac 是我在 juggernaut 机器上的个人用户帐户

mymac:x:1000:1000:juggernaut,,,:/home/mymac:/bin/bash
Run Code Online (Sandbox Code Playgroud)

那 x, 1000 , 1000 是什么意思?和后面的逗号?

以此类推,也解释一下:

root:x:0:0:root:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)

mur*_*uru 15

来自man 5 passwd

/etc/passwd contains one line for each user account, with seven fields
delimited by colons (“:”). These fields are:

·   login name
·   optional encrypted password
·   numerical user ID
·   numerical group ID
·   user name or comment field
·   user home directory
·   optional user command interpreter
Run Code Online (Sandbox Code Playgroud)

x将是可选的加密密码,联机帮助页进一步说明:

The encrypted password field may be blank, in which case no password is
required to authenticate as the specified login name. However, some
applications which read the /etc/passwd file may decide not to permit
any access at all if the password field is blank. If the password field
is a lower-case “x”, then the encrypted password is actually stored in
the shadow(5) file instead; there must be a corresponding line in the
/etc/shadow file, or else the user account is invalid. If the password
field is any other string, then it will be treated as an encrypted
password, as specified by crypt(3).
Run Code Online (Sandbox Code Playgroud)

逗号分隔GECOS 字段

GECOS 字段的典型格式是一个以逗号分隔的列表,顺序如下:

  1. 用户的全名(或应用程序名称,如果帐户用于程序)
  2. 楼房号或联系人
  3. 办公室电话
  4. 任何其他联系信息(寻呼机号码、传真等)

所以:

mymac:x:1000:1000:juggernaut,,,:/home/mymac:/bin/bash
|     |  |    |    |             |             |
|     |  |    |    |             |             Login shell
|     |  |    |    |             Home directory
|     |  |    |    GECOS fields (full name, etc.)
|     |  |    Primary Group id
|     |  User ID
|     Encrypted password indicator
Username
Run Code Online (Sandbox Code Playgroud)

  • @ juggernaut1996 那么,我应该为您复制粘贴另一个联机帮助页吗?[`man 5 shadow`](http://manpages.ubuntu.com/shadow.5) 中的解释非常清楚。 (2认同)
  • @Noumenon https://askubuntu.com/q/647051/158442 (2认同)