Configuring SSH Host Key Policies
To enhance the security of your SSH connections, you can configure various host key policies that define how the SSH client should handle host key verification. These policies can be set at the system level or the user level, depending on your requirements.
SSH Host Key Policy Options
The most common SSH host key policy options include:
-
StrictHostKeyChecking: This option determines how the SSH client should behave when the host key presented by the server does not match the stored key.
StrictHostKeyChecking=yes
: The SSH client will refuse to connect if the host key does not match, raising a "host key verification failed" error.
StrictHostKeyChecking=no
: The SSH client will automatically accept the new host key without verification, which is not recommended for security reasons.
StrictHostKeyChecking=ask
: The SSH client will prompt the user to decide whether to accept the new host key.
-
UserKnownHostsFile: This option specifies the location of the known_hosts
file, where the SSH client stores the host keys.
- Default location:
~/.ssh/known_hosts
-
GlobalKnownHostsFile: This option specifies the location of the global known_hosts
file, which is used for system-wide host key management.
- Default location:
/etc/ssh/ssh_known_hosts
Configuring SSH Host Key Policies
You can configure the SSH host key policies in the SSH client configuration file, typically located at ~/.ssh/config
for user-level settings or /etc/ssh/ssh_config
for system-wide settings.
Example configuration:
Host *
StrictHostKeyChecking ask
UserKnownHostsFile ~/.ssh/known_hosts
In this example, the SSH client is configured to:
- Ask the user whether to accept a new host key when the presented key does not match the stored one.
- Use the
~/.ssh/known_hosts
file to store the host keys.
You can also set the host key policy for specific hosts or domains by using the Host
directive in the configuration file.
Host example.com
StrictHostKeyChecking yes
This configuration will enforce strict host key checking for connections to the example.com
domain.
By configuring the appropriate SSH host key policies, you can ensure that your SSH connections maintain a high level of security and protect against potential attacks.