Budget-friendly, full-performance, fully equipped servers in any desired location.
ExploreBudget-friendly, full-performance, fully equipped servers in any desired location.
ExploreServer security is best improved by strengthening SSH access without closing the working connection: first verify existing access, test key-based login, and then change risky options one at a time. This guide is intended for Linux servers where you have administrative access; you may not have permission to change SSH settings in a shared hosting panel.
Before starting, check which account you use to connect to the server, whether that account has sudo privileges, and whether a second administrative session is currently working. Being able to open a new terminal without closing the active connection is the most important safety measure for preventing a faulty SSH setting from locking you out completely.
Also save the current SSH configuration file and the values you plan to change somewhere secure. Although the location can vary by distribution, SSH server settings are found in /etc/ssh/sshd_config or in additional configuration files under that directory in most Linux installations. Do not change multiple settings at once on a production server if you do not have a backup or rollback plan.
First determine the connection method and which settings the server considers active. A read-only configuration check that can be run with administrative privileges can help you distinguish comment lines and options defined more than once in the files. For example, the following command can be used to validate the configuration:
sshd -t
If this command completes without output, the configuration syntax may be valid; this does not necessarily mean that the connection is secure or that the service is ready to be reloaded. If you receive an error message, do not reload the service. Correct the reported setting and run the same validation again. Look for evidence of SSH login attempts in the distribution's system logs, service logs, or the provider's server monitoring screen. Note the time, as this is necessary to avoid confusing old and new records.
PasswordAuthentication to no in the configuration and make only this change. If password login is still accepted, another additional configuration file may be overriding the setting; in that case, inspect all files and the distribution's effective settings. If the authentication record shows that the key was accepted, try opening a new session. If it fails, restore the value before closing the existing session.sudo works with a separate administrative account, you can set PermitRootLogin to no in accordance with your distribution policy. Do not apply this if logging in with the root account is your only access path; first create and test a separate authorized account. The expected result is that administrative operations are performed through a normal user account and auditable use of sudo.sshd -t again after the change. If there is no error, use the option to reload the SSH service in the distribution's service management tool; if reloading is supported instead of restarting, prefer it to avoid unnecessarily interrupting connections. Remember that service management can vary by provider.If the log shows a successful password session even though password login is disabled, investigate a non-SSH access service, panel, or provider-specific console; repeatedly changing the SSH setting will not explain this result. If, on the other hand, the log says that the key file could not be read or was unauthorized, do not reopen password login. Instead, check that the key belongs to the correct user, that the file permissions comply with the distribution's policy, and that the user can access the home directory. Broad permission changes or publicly accessible file permissions are not a secure fix.
Suppose you have only one administrative account, a second SSH session can be opened with that account using a key, and the logs show that earlier attempts used a password. In this case, it is reasonable to first save the current configuration and disable only password login, because the key path is already demonstrably working. If the new attempt succeeds with the key and fails with the password, restricting root login could be the next step. If the second session also fails, restoring the password setting before changing the root setting is the safe rollback path.
On the other hand, if an automation tool, monitoring system, or backup task connects to the server using a password, the same change may stop those services. First verify which authentication method the relevant task uses and whether it supports keys. Additional layers such as a provider-dependent console, multifactor authentication, or IP restrictions may be present; they do not replace the SSH configuration, but they should also be tested as part of the access model.
If a new session cannot be opened, a configuration error appears in the logs, or access for an unexpected user is interrupted, do not close the active session. Restore the original value you saved, run the configuration validation again, and retest only the single factor you corrected. If the problem continues, use the provider's recovery console or authorized server management to revert the latest change; do not paste credentials or sensitive data from the logs into a public location.
The first safe step is to record today's existing SSH connection method and the relevant values in the configuration. If you are considering moving to a managed server, you can review the server rental options page, but separately verify who actually manages the security settings.
Copyright © 2026 All Rights Reserved
