Non-Unix file formats in critical system files can prevent login to a Linux instance. Use instance health diagnosis to identify and repair affected files.
Prerequisites
An instance health diagnosis has been performed on the Linux instance.
Problem analysis
Symptoms
The instance fails to start or cannot be connected to. Instance health diagnosis reports incorrect file formats causing logon failures. Commonly affected files include /etc/passwd, /etc/shadow, and /etc/ssh/sshd_config. The diagnosis result shows the path to the affected file.

Common causes
-
The file was edited on Windows and uploaded to the Linux instance, such as through FTP or SFTP.
-
An incompatible text editor introduced incorrect line feeds when modifying the file.
Solution
-
Connect to the instance as a user with sudo permissions.
When a repair disk is attached, you can only connect to the instance through a VNC connection.
View the mount information of the original system disk on the faulty ECS instance.
On the repair disk that is temporarily attached to the ECS instance, the file systems of the original system disk of the instance are mounted to a temporary directory. You can use one of the following methods to view the temporary directory:
In the Associated Instances section on the disk details page of the original system disk, view the temporary directory. Example:
/tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse****.bp19bspzms79kqse****is the serial number of the original system disk of the ECS instance.Run the mount command on the repair disk to view the temporary directory. For example, if the device name of the original system disk of the faulty ECS instance is /dev/vda, run the following command:
mount | grep /dev/vdaThe following command output is returned:
/dev/vda1 on /tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse**** type ext4 (rw,relatime)
-
Switch to the chroot environment of the original system disk.
For example, if the temporary path is /tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse****, run:
chroot /tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse****NoteIf the
chrootcommand fails, verify the mount path. You can also bind-mount required directories:mount --bind /dev /mnt/repair_disk/dev mount --bind /proc /mnt/repair_disk/proc -
Edit the affected file with vim in the chroot environment.
ImportantBack up critical system files before modifying them. Example:
cp /etc/passwd /etc/passwd.bak.Before editing, note the following:
-
Files you edit are on the original system disk. To edit files outside the mount target, run exit to leave the chroot environment first.
-
In the chroot environment, you do not need the /tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse**** prefix in commands.
For example, to edit /etc/passwd, run vim /etc/passwd directly without the /tmp/ecs-offline-diagnose_disk-bp19bspzms79kqse**** prefix.
vim [$File]Replace [$File] with the path of the affected file. Example with /etc/passwd:
vim /etc/passwd -
-
Change the file format.
-
Press Shift+:, enter
set ff=unix, and press Enter.
-
Press Shift+:, enter
wq, and press Enter to save and exit.
-
- After the files are restored, exit the chroot environment and check the state of the abnormal instance.
- Run the exit command to exit the chroot environment.
- Go to the Troubleshooting page in the ECS console. On the Instance Health Diagnosis tab, detach the repair disk from the instance and start the instance.
- Connect to the instance and confirm that you are connected to the instance.