Accidentally deleted / etc / passwd file how to do

In Linux / etc / passwd file, each user has a corresponding rows, it records the basic attributes of users. System administrators often exposed to amend this document to complete user management.

For example:

root❌0:0:root:/root:/bin/bash

We can see from the above example, / etc / passwd in a row corresponds to a user, each of the rows in turn colon (:) 7 fields, the format and explained as follows:

1. Username: Password: user ID: Group ID: Annotated Description: home directory: login Shell

2. User name (login_name): is a string representing the user account. Generally no longer than eight characters, and the uppercase and lowercase letters and / or numbers. Login name can not contain a colon (:) colon because here is the delimiter. For compatibility reasons, the login name is best not contain a dot character, and does not use a hyphen (.) (-) and plus (+) starts.

3. password (passwd): some systems, the storage of the encrypted user password. Although this field is stored only encrypted password string, not expressly, but due to the / etc / passwd file can be read to all users, so this is still a security risk. So now many Linux systems (such as SVR4) use the shadow technique, the user password after the real encryption stored in the / etc / shadow file, and in the password field of / etc / passwd file is stored in only one special characters, such as "x" or "*."

4. The user identification number (UID): is an integer, within the system to use it to identify the user. Under normal circumstances it with the user name is one to one. If the user identification number corresponding to the number of user names are the same, within the system will treat them as the same user, but they can have different passwords, different home directories, and so on different login Shell. It ranges 0-65535.0 super root user identification number, 1-99 retained by the system, as account management, common user identification number 100 from the beginning. On Linux systems, this limit is 500.

The group ID (GID): field of the record is the group they belong to. Which corresponds to a record / etc / group file.

6. Notes description (users): field records some user's personal circumstances, such as the user's real name, phone, address, etc., this field is no practical use. In different Linux system, the format of this field is not uniform. In many Linux systems, this field is stored in the comment section of any description text, used finger command output.

7. The user's home directory (home_directory): the initial operation is the user's directory, it is the directory in which the user after logging in to the system. In most systems, each user's home directory are organized in the same specific directory, and the name of the user's home directory is the user's login name. Each user has their own home directory read, write, execute (search) permission, another user access to this directory is set depending on the circumstances.

8. Log Shell (Shell): After the user logs in, to start a process, the user is responsible for the operation passed to the kernel, the process is run after the user logs on to the system command interpreter or a particular program, namely Shell. Shell is the interface between the user and Linux systems. There are many Linux-Shell, each with different characteristics. If you do not specify Shell, the system uses sh as the default login Shell, that is, the field is / bin / sh.

Shell user login can be specified for a particular program (this program is not a command interpreter). Using this feature, we can restrict users to running specific applications, at the end of the application is running, users will automatically exit the system. Some Linux systems require only those registered in the system program to appear in this field.

So when we operate LInux, if not accidentally deleted / etc / passwd file, how do we solve it?

A. If you do not reboot the system after deleted, then we only need to / etc / passwd- this primer to copy the file / etc / passwd to

cp /etc/passwd- /etc/passwd

II. If we shut down the system after deleting a file, when opened will find the entrance

Accidentally deleted / etc / passwd file, how do accidentally deleted / etc / passwd file how to do

Then we solved:

1. When e GRUB boot according to enter the edit mode, linux16 modify that row ro rw rd.break

2.ctrl + x execution

3. After the single-user mode to modify root path, program copy will come primer

chroot /sysroot

cp /etc/passwd- /etc/passwd

4. Because the copy came in the security context and when the pro catalog file does not match, then we need to turn off selinux

vim /etc/sysconfig/selinux

selinux = disabled

5. Two exit to exit now and restart the host roots, back to normal


Guess you like

Origin blog.51cto.com/14414295/2480963