嵌入式Linux往往没有用户管理,shell登陆也仅仅是给开发者用的。因此,像Android,无需输入用户名,可以直接登入shell。如果你需要用户管理(嵌入式Linux通常只需要root),可以添加/etc/passwd。login shell读取输入的用户名和密码后,在passwd文件中验证输入的合法性。
添加passwd前,必须了解passwd的格式。
The /etc/passwd contains one entry per line for each user (or user account) of the system. All fields are separated by a colon (:) symbol. Total seven fields as follows.
Generally, passwd file entry looks as follows (click to enlarge image):
![]()
(Fig.01: /etc/passwd file format - click to enlarge)
- Username: It is used when user logs in. It should be between 1 and 32 characters in length.
- Password: An x character indicates that encrypted password is stored in /etc/shadow file.
- User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.
- Group ID (GID): The primary group ID (stored in /etc/group file)
- User ID Info: The comment field. It allow you to add extra information about the users such as user's full name, phone number etc. This field use by finger command.
- Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /
- Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell.
我的passwd如下:
root::0:0:root:/root:/bin/sh