在Linux中,什么是/ etc / passwd文件?

/etc/passwd in Linux is a file that stores the list of users on the system along with important information regarding these users. Identifying users uniquely is essential and necessary at the time of login. /etc/passwd is used by Linux system at the time of login. The file should be readable by all users but write permission should only belong to the root user.

Linux中的/ etc / passwd是一个文件,用于存储系统上的用户列表以及有关这些用户的重要信息。 登录时唯一地标识用户是必不可少的。 / etc / passwd在登录时由Linux系统使用。 该文件应为所有用户可读,但写许可权应仅属于root用户。

了解/ etc / passwd文件 (Understanding the /etc/passwd file)

To view the contents of the file use cat command.

要查看文件的内容,请使用cat命令。


$ cat /etc/passwd
Etc/passwd File

The output will look something like this. Here each line represents a user. Each user has a list of parameters separated by ‘:’

输出将如下所示。 每行代表一个用户。 每个用户都有一个用“:”分隔的参数列表

The seven fields are :

七个字段是:

  • Login name

    登录名
  • Encrypted Password

    加密密码
  • UID number

    UID号
  • GID number

    GID号码
  • GECOS

    GECOS
  • Home directory

    主目录
  • Login shell

    登录外壳

Let’s see what each of them mean :

让我们看看它们各自的含义:

  1. Login name: The unique name given to a user. It is case sensitive.

    登录名 :给用户的唯一名称。 区分大小写。
  2. Encrypted Password: This field is for the encrypted password. However, in most modern Linux systems, the password is stored in a shadow file named /etc/shadow. The ‘x’ in the second field represents that the password is stored in a shadow file.

    加密密码 :此字段用于加密密码。 但是,在大多数现代Linux系统中,密码存储在名为/ etc / shadow的影子文件中。 第二个字段中的“ x”表示密码存储在影子文件中。
  3. UID number: A unique ID assigned for each user. The system identifies a user by its UID number. The root user gets UID 0 which is reserved. UID 1-99 are reserved for predefined accounts. These are also called fake logins. In most Linux systems UID for new users starts from 1000.

    UID号 :为每个用户分配的唯一ID。 系统通过其UID号标识用户。 根用户获得保留的UID 0。 UID 1-99保留用于预定义帐户。 这些也称为假登录。 在大多数Linux系统中,新用户的UID从1000开始。
  4. GID number: GID is used to identify the group user belongs to. Information about groups is stored in /etc/group file. In Linux, a user can belong in up to 16 groups.

    GID号 :GID用于标识组用户所属。 有关组的信息存储在/ etc / group文件中。 在Linux中,一个用户最多可以属于16个组。
  5. GECOS: stands for General Electric Comprehensive Operating Supervisor. This field allows the admin to store additional information about the user. This field can have multiple entries in a comma-delimited list. Information such as full name, phone number, the designation can be stored in this field.

    GECOS :代表通用电气综合运营主管。 该字段允许管理员存储有关用户的其他信息。 该字段在逗号分隔列表中可以有多个条目。 姓名,电话号码,名称等信息可以存储在此字段中。
  6. Home directory: This field contains the absolute path to the user’s home directory. When a user logs in, the system puts him/her directly in his/her home directory.

    主目录:此字段包含用户主目录的绝对路径。 用户登录后,系统会将其直接放置在其主目录中。
  7. Login shell: This field is for specifying the program that will run automatically whenever the user logs in. It’s typically a command interpreter (shell).

    登录外壳程序 :此字段用于指定用户登录时将自动运行的程序。它通常是命令解释器(外壳程序)。

创建一个用户 (Create a user )

We can use the useradd command to create a new user. Make sure to run the command with root access.

我们可以使用useradd命令创建一个新用户。 确保以root用户访问权限运行命令。


$ useradd Adam 

This creates a user by the name Adam.

这将创建一个名为Adam的用户

修改GECOS字段 (Modify GECOS field)

To modify the GECOS field for Adam, use usermod command.

要修改Adam的GECOS字段,请使用usermod命令。


$ usermod -c "DevOp expert" Adam

显示特定用户的条目 (Display entry for a particular user)

From the etc/passwd file to get the entry for a single user use grep command.

使用grep命令从etc / passwd文件获取单个用户的条目。


$ grep Adam /etc/passwd
Grep Command For Adam

As we can see that GECOS field has been successfully updated for user Adam.

如我们所见,GECOS字段已成功为用户Adam更新。

We break the values into their respective fields :

我们将值分为各自的字段:

  • Login name: Adam

    登录名: Adam
  • Encrypted Password: x (shadow file)

    加密密码: x (影子文件)
  • UID number: 1001

    UID号: 1001
  • GID number: 1002

    GID号: 1002
  • GECOS: DevOp expert

    GECOS: DevOp专家
  • Home directory: /home/Adam

    主目录: / home / Adam
  • Login shell: /bin/sh

    登录shell: / bin / sh

结尾词 (Ending words)

As a Linux administrator, it is important to know the /etc/passwd file at the back of your hand. Understand what each field means and keep a track of users on the system. To learn more about /etc/passwd file refer to this Wikipedia page for passwd command.

作为Linux管理员,了解手背的/ etc / passwd文件非常重要。 了解每个字段的含义,并跟踪系统上的用户。 要了解有关/ etc / passwd文件的更多信息,请参阅Wikipedia页面上的passwd命令。

翻译自: https://www.journaldev.com/41380/etc-passwd-file-in-linux

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值