Causes
Errors in the SSH configuration file can prevent the service from starting:
Syntax error: A configuration option is misspelled, or its value is outside the allowed range or a predefined list (for example, on/off, true/false, or a specific numeric range).
File encoding error: The file contains a Byte Order Mark (BOM) or uses CRLF line endings.
Solutions
Solution 1: Fix errors in the SSH configuration file
Log on to an ECS instance using a VNC connection.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select VNC. Enter the username and password to log on to the ECS instance.
Diagnose the SSH service configuration.
sudo /usr/sbin/sshd -tAnalyze the error message returned by the command. The message specifies the file, line number, and error type:
# Example 1: A deprecated configuration item is used /etc/ssh/sshd_config: line 82: Bad configuration option: RSAAuthentication # Example 2: Incorrect value for a configuration item /etc/ssh/sshd_config: line 23: bad value for Port "222222"Modify the configuration file.
sudo vim /etc/ssh/sshd_configHandle deprecated configuration options: OpenSSH updates sometimes deprecate older options. Comment out or delete the relevant lines.
RSAAuthentication: Deprecated in OpenSSH 7.0 and later.UsePrivilegeSeparation: Deprecated in OpenSSH 7.5 and later, as it is now the default.
Correct syntax errors: Use the error message to find and correct the invalid syntax or value on the specified line.
Check and fix file encoding: A configuration file copied from a Windows system might contain a Byte Order Mark (BOM) or use CRLF line endings, which cause parsing failures.
To check the line ending format: Enter
:set fileformat?.
If the output isfileformat=dos, the file contains CRLF line endings. To fix it, enter:set fileformat=unix.To check for a BOM: Enter
:set bomb?.
If the output isbomb, the file contains a BOM. To fix it, enter:set nobomb.
If you find none of these issues, or if the configuration file is severely corrupted, you can reinstall the SSH service.
Validate the configuration.
If the command returns no output, the configuration is correct.
# Verify the configuration sudo /usr/sbin/sshd -tRestart the SSH service.
sudo systemctl restart sshdVerify the service status.
If the output includes
active (running), the service started successfully.sudo systemctl status sshd
Solution 2: Reinstall the SSH service
Log on to an ECS instance using a VNC connection.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select VNC. Enter the username and password to log on to the ECS instance.
Back up the configuration file.
Reinstalling the SSH service removes all custom configurations, such as modified ports or key-based authentication settings.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup-$(date +%Y%m%d-%H%M%S)Uninstall the SSH service.
sudo rpm -e openssh-serverInstall the SSH service.
After installation, migrate your custom configurations from the backup to the new configuration file.
sudo yum install openssh-serverStart the SSH service.
sudo systemctl start sshdVerify the service status.
If the output includes
active (running), the service started successfully.sudo systemctl status sshd