Skip to content

47-Day Certificates Are Coming. Are You Ready?

Act Now →

A Guide to Protect and Manage SSH Keys to Mitigate Security Risks

a-guide-to-protecting-and-managing-ssh-keys-to-mitigate-security-risks

Secure Shell (SSH) keys are cryptographic access credentials used in the SSH protocol for remote server access, secure file transfer, and server-to-server authentication across modern infrastructure, including Infrastructure-as-a-Service platforms like AWS, Google Cloud, and Azure. SSH keys matter for security because large enterprises may have more than one million SSH keys in their environment, and unlike passwords or certificates, SSH keys have no built-in expiration date and no standard revocation mechanism. An unmanaged SSH key from a former employee can remain valid as a permanent backdoor indefinitely unless explicitly removed. The recommended action: begin with full discovery of all SSH servers and all authorized keys in your environment; map each key to an owner; implement policies governing key generation, rotation, and revocation; disable root login; and use SSH Secure to manage the SSH key lifecycle at scale. For the technical explanation of how SSH keys work, see the sister blog How Do Secure Shell (SSH) Keys Work. For enterprise SSH key management, see SSH Secure.

Quick Answer: Why Is SSH Key Management Critical?

SSH keys are access credentials with no built-in expiration and no standard revocation mechanism, making unmanaged SSH key environments a persistent security liability. Large enterprises may have more than one million SSH keys, many belonging to former employees, shared across multiple users, embedded in applications, or simply forgotten after server migrations. Any of these unaccounted keys can be used by an attacker who has obtained the corresponding private key to gain persistent access to critical infrastructure, often without triggering alerts because the connection uses a valid credential. The three essential controls are: discover and inventory all SSH keys; implement policies for key rotation and revocation; and disable root SSH login so all privileged access is auditable.

What Are SSH Keys?

SSH keys are cryptographic key pairs used for authentication in the Secure Shell (SSH) protocol. The most common choice for SSH key encryption is RSA 2048-bit, which provides security comparable to a 617-digit password. SSH key pairs consist of a public key and a private key: the public key is placed on the remote server, and the private key is held by the client. Authentication succeeds when the client proves possession of the private key corresponding to the public key authorized on the server. Generating an SSH key pair differs by operating system: on Windows, users generate keys using an SSH client such as PuTTY; on Mac and Linux, keys are generated in a terminal window using the ssh-keygen command.

SSH keys are always available in pairs. There are three different types of SSH keys, distinguished by who or what possesses them:

  • User Keys

    If the private and public keys are held by a specific user, the key pair is referred to as User Keys. The public key is placed in the authorized_keys file on the remote server; the private key stays on the user’s system. User keys authenticate individual users to remote servers.

  • Host Keys

    If the private and public keys are on the remote system (the server), the key pair is referred to as Host Keys. Host keys identify the server to connecting clients, allowing the client to verify they are connecting to the correct server and not a man-in-the-middle. When you connect to a new SSH server for the first time and are shown a fingerprint to confirm, you are verifying the host key.

  • Session Keys

    Session keys are symmetric encryption keys used when a large amount of data is being transmitted during an active SSH session. Unlike user and host keys, session keys are generated fresh for each connection and are not stored persistently. This limits the impact of session key compromise to the duration of the specific session in which the key was used.

How Does SSH Key Authentication Work?

After a key pair is generated and the public key is placed on the remote server, the SSH authentication process works as follows. The user initiates a connection specifying the SSH username and IP address of the remote system. The SSH protocol determines which public key to use for authentication based on the specified username. The remote server encrypts a challenge message using the client’s public key and sends it to the client. The client decrypts the challenge using the private key stored on the user’s system. The decrypted challenge is combined with the session ID and returned to the server. If the returned value matches the server’s expected value, authentication succeeds and access is granted.

The security of this process depends entirely on the private key remaining secret. If an attacker obtains the private key, they can authenticate to any server that holds the corresponding public key, without a password and without triggering any alert that a different user is authenticating.

Tailored Advisory Services

We assess, strategize & implement encryption strategies and solutions customized to your requirements.

Managing SSH Keys

There are several millions of SSH keys in use across enterprise environments, primarily in organizations that use Infrastructure-as-a-Service platforms and large-scale server infrastructure. An effective SSH key management system is essential for reducing security risk across development and production environments. Effective management requires controlling the SSO provider, directory services, and system management solutions, and integrating SSH key governance into the broader identity and access management program.

Risks Associated with SSH Keys

There are many risks and vulnerabilities involving SSH keys. The following five are critical and should not be ignored:

SSH Key Tracking Troubles

A large enterprise may have more than one million SSH keys, and it is practically impossible to track or manage each key without automated tooling. End users can create new SSH keys or duplicate them without central approval or a formal issuance process, unlike certificates or passwords which require a CA or directory service to issue. Once a large number of unmanaged SSH keys accumulate, tracking them becomes critical when development servers are migrated to production, when employees leave without revoking their keys, or when applications embed keys in scripts. Unaccounted SSH keys can provide attackers with long-term privileged access to corporate resources, and abandoned keys from former employees can function as permanent backdoors.

Sharing SSH Keys Is Trouble

For efficiency, SSH keys are often shared or duplicated across employees or servers. A single SSH key can have multiple instances granting access to all machines in an enterprise. Key duplication creates complicated many-to-many relationships between private keys and servers that reduce security, because rotating and revoking shared keys without disrupting all users who share them is operationally difficult. Key sharing also reduces audibility and non-repudiation: when multiple users share a private key, log entries cannot reliably attribute actions to a specific individual.

Static SSH Keys

Rotating more than one million SSH keys is operationally demanding. Many IT administrators rarely change or redistribute keys out of concern that a critical system or user may lose access during the rotation. These operational concerns lead to an accumulation of static SSH keys that have not been rotated for months or years. Static keys give attackers more time to discover and exploit a compromised key, and move laterally through the organization using it to access sensitive assets without triggering key rotation alerts.

Embedded SSH Keys

SSH keys are frequently embedded inside applications and scripts to enable automated server-to-server authentication. Embedded keys are particularly difficult to rotate because the application code and the key must be updated in coordination to prevent service outages. This coordination difficulty leads to embedded keys remaining static indefinitely, creating persistent backdoors in application code that can be exploited if the code is accessed by an attacker.

Weak SSH Configuration

SSH client and server implementations like OpenSSH include configuration parameters that many IT administrators leave at default values. Default settings such as allowing port forwarding, permitting root login, and accepting password authentication alongside key-based authentication all increase security risk. A weak SSH configuration can expose the server to brute force attacks and allow attackers to escalate privilege or move laterally through the network once they have any valid SSH access.

Security Vulnerabilities of SSH

  • Brute force and malware attacks

    Attackers target SSH keys to gain lateral movement within an enterprise, launch brute force attacks against SSH services that allow password authentication, and install malware by creating backdoors using compromised SSH keys or misconfigured SSH servers. Once an attacker has a valid SSH private key or has brute-forced a weak password on an SSH server, they have authenticated access that is indistinguishable from legitimate access in the server logs.

  • SSH session hijacking and unauthorized access

    Attackers can hijack an active SSH session by exploiting the trusted communication established between systems and gaining access to the user’s SSH socket. This is done by exploiting default configurations that allow socket forwarding, or by compromising the client system and accessing the SSH agent socket. Avoiding default configurations and restricting SSH agent forwarding to specific trusted hosts significantly reduces this risk.

How to Mitigate SSH Security Attacks

  1. Discover and map keys

    Discover all SSH servers, public keys, and private keys that have authorization to grant SSH access. Run frequent network scans using SSH discovery tools to locate and inventory all authorized keys. Build a centralized repository that maps each public key to the corresponding user or system that holds the private key, and update this map continuously. Mapping the key-to-user and key-to-server relationships is the foundation on which all other SSH key management controls depend.

  2. Control SSH keys and access

    Implement SSH key management policies covering key generation standards, maximum key lifetime, rotation schedules, and revocation procedures for departing employees and decommissioned systems. Assign the minimum required access level to each key pair: user keys should grant access only to the specific servers the user needs; embedded keys should have access only to the systems the application requires. Use directory services to enforce required access clearances and centralize key authorization decisions. See SSH Secure for automated SSH key lifecycle management.

  3. Disable root login

    The root account on UNIX-based systems has unrestricted access to all system resources. Attackers specifically target root login to gain unlimited access to critical systems. Configure all SSH servers with PermitRootLogin set to no, requiring users to authenticate as named user accounts and use sudo or su for privilege escalation. This ensures that all privileged actions are associated with a named user account and creates an audit trail that makes forensic investigation of unauthorized privileged actions possible.

SSH Key Remediation Checklist

  • Complete a full discovery scan of all SSH servers and all authorized_keys entries in the environment
  • Map each public key to an owner (user or system); flag keys with no identifiable owner for immediate investigation and revocation
  • Revoke all SSH keys belonging to former employees identified during discovery
  • Identify and document all embedded SSH keys in application code and scripts; begin planning a rotation schedule that coordinates application updates
  • Implement an SSH key management policy with defined maximum key lifetime and mandatory rotation periods
  • Configure all SSH servers with PermitRootLogin no; verify the change is applied and effective
  • Disable password-based authentication on all SSH servers; enforce key-based authentication only
  • Restrict SSH agent forwarding to specific trusted hosts; disable it by default
  • Disable default port forwarding on servers where it is not required
  • Set up continuous SSH key discovery and monitoring to maintain inventory accuracy as keys are created or changed
  • Integrate SSH key offboarding into the employee departure process to ensure immediate key revocation
  • Review and update the SSH key inventory quarterly

Conclusion

If IT administrators maintain proper audit trails ensuring that all SSH keys in use adhere to defined policies, this provides the transparency needed to detect unauthorized keys, respond to compromised credentials, and make appropriate modifications for key generation, rotation, and revocation. SSH key management requires the same systematic governance that organizations apply to certificate lifecycle management: discovery, inventory, access control, and automated rotation. For enterprise SSH key lifecycle management, see SSH Secure. For the technical explanation of how SSH keys work, see How Do Secure Shell (SSH) Keys Work.

Frequently Asked Questions

What are the three types of SSH keys and how do they differ?

The three types are: User Keys (held by the user, authenticate users to servers); Host Keys (held by the server, allow clients to verify server identity and prevent man-in-the-middle attacks); and Session Keys (symmetric keys generated fresh for each connection, used to encrypt session traffic, not stored persistently).

Why is tracking SSH keys difficult in large enterprise environments?

Unlike certificates or passwords, SSH keys can be created and duplicated by end users without central approval, a formal issuance process, or any record in a central system. Large enterprises may have more than one million SSH keys, many from former employees or embedded in applications. Without automated discovery tools, visibility degrades rapidly as keys accumulate, creating persistent unauthorized access risks.

What is SSH key sharing and why is it a security risk?

SSH key sharing is duplicating a single key pair across multiple users or servers. A shared key may grant access to many machines simultaneously; rotating or revoking it disrupts all users who depend on it. Key sharing also degrades audibility and non-repudiation because logs cannot reliably attribute actions to a specific individual when multiple people share one private key.

What steps are most effective for remediating an environment with unmanaged SSH keys?

The four most effective steps are: (1) Full discovery scan to identify all SSH servers and authorized keys; (2) Map every public key to a specific owner or system; (3) Revoke all keys from former employees and keys with no identifiable owner; and (4) Implement policies covering key generation standards, maximum key lifetime, rotation schedules, and mandatory revocation procedures for departing employees.

How does SSH key management relate to PKI and certificate management?

Both SSH keys and PKI certificates are cryptographic credentials requiring lifecycle management, but SSH keys have no built-in expiration and no standard revocation mechanism, making unmanaged SSH keys a more persistent risk than expired certificates that fail automatically. SSH certificates (binding SSH public keys to identities with expiration dates) are a hybrid approach bringing PKI-style governance to SSH. Organizations with mature certificate lifecycle management should apply comparable inventory and access control practices to SSH keys.