Instead of using the same key to decrypt and encrypt connections, public key encryption uses a public and private key. The public key is available to the public, and the private key is kept safe from any third party. Only the user with the private key in the public-private key pair can decrypt data encrypted with a public key. This system improves security of Secure Shell (SSH) connections when administrators remotely connect to servers and workstations.

What Is Public Key Authentication?

Two keys are generated in public key authentication. The private key can be used to encrypt and decrypt data. The public key can only encrypt data, and the private key can decrypt data encrypted with the public key. Think of a key as a more sophisticated password, only it’s cryptographically secure and the password is not in cleartext or decipherable by a third party.

Public key authentication requires two keys, but it’s not uncommon for administrators to have multiple public-private key pairs for multiple systems. Keys are often rotated every 30, 60, or 90 days depending on the importance of the system. Administrator keys for critical systems hosting sensitive data or important applications should have their keys rotated more frequently, but keys should always rotate to reduce the window of opportunity for an attacker should attackers steal them. When users are no longer employed at an organization, keys should be revoked and invalidated.

To add a layer of security to infrastructure, users must enter a password to access keys. Keys should always be considered highly sensitive data and must be protected with stringent security. When a user opens SSH, the system will prompt them for a password to use the key files.  

What Is Secure Shell (SSH)? 

Secure Shell (SSH) is a protocol specifically designed for administrators to remotely control a server or workstation. The protocol must be configured and installed on the target machine. One of the configurations important in security is the use of credentials and encryption. Credentials can be stolen in phishing campaigns. However, keys are stored files used in place of standard username and password authentication, making them more secure than using simple credentials.

Encryption is a method used to secure information transferred between the administrator’s client machine and the host server. SSH is the protocol used to remotely control the machine. Public key authentication is a secure method for validating an administrator’s account. SSH supports public key authentication, and it’s a much more secure way to remotely authenticate and control a server or workstation. Authentication is a requirement when connecting to an SSH host, but you can choose standard credentials instead of public key authentication. 

How to Implement Threat Modeling in Your DevSecOps Process

Configuring SSH with Public Key Authentication

SSH public key authentication allows users to log into an SSH/SFTP account with a key instead of a password. Before you can use public key authentication with SSH, you need to generate a private and public key pair. After you have the public key stored, you can use the private key stored on your local workstation to authenticate on the server host. You can generate keys on your local client machine or the server, but be sure to copy the keys to your own workstation where you’ll be connecting via SSH. Never store the private key on the server. The private key should be kept safe on your own computer. 

For Linux, it’s more convenient to generate keys on your local machine rather than the server. Windows users can generate keys on either the client or host machine, but do not leave private keys stored on the server if you generate them on the server.

To generate a key:

  1. Type ssh-keygen in the command prompt. A public and private key is generated and stored on your local machine.
  2. Enter a filename. Note that creating a key file with the same name as a previous key file will overwrite the original, so make sure you do not have another active key already stored. 
  3. Enter a passphrase for the key file. You’ll need this passcode to access the key file when you connect to SSH.
  4. If you performed these steps on the server, copy the key files to your local machine and delete the private key from the server. 

Public Key Infrastructures

To use authentication within an organization, administrators can use free open source solutions or commercially available solutions. A commercial public key infrastructure (PKI) solution usually has a fee, but free solutions might have restrictions on commercial use. Always check licensing agreements before installing a PKI solution in a commercial environment.

A few open source solutions:

A few commercial solutions:

Benefits and Drawbacks of Public Key Authentication

The increase in security for remote machines is public key authentication’s biggest advantage. Digital signatures included with PKI validate user identities without adding expensive authentication software or hardware. The SSH protocol natively allows for authentication with a public key, so no third-party applications are necessary. SSH and public key encryption scale without causing any performance problems on the target server, so administrators can work on a remote server even with thousands of connections during production hours. 

Put it all together and you have an authentication scheme that greatly simplifies group collaboration among developers and administrators. A single admin can access multiple accounts without the need for multiple passwords. Multiple developers can be granted access to the same system without having to share a single password between them. Revoking access to other users is as simple as deactivating that user’s key. 

Using keys instead of standard credentials requires a small learning curve for users unfamiliar with the system. If keys are lost, users have no failover for authentication if standard credential access is disabled on the remote server. Public key authentication isn’t as intuitive as entering a username and password, so implementing it company-wide might have its challenges as users figure out how to use the new system.


Critical servers on the network need the highest level of security when administrators remotely access them. Public key authentication is a more secure and scalable way to deploy SSH across servers and keep them secure from unauthorized access. SSH works with public key authentication natively, so it’s an easy configuration to add to administrator workflows.