SSH Generate Key: Create and Register a Client Key Pair
To generate an SSH key pair for an authorized account, create a private and public key on the client, protect the private key with a passphrase, and register only the public key with the server. Test a separate login using the new key before removing an older one.
Choose the key and its purpose
The practical answer to an “ssh generate key” task is the OpenSSH ssh-keygen utility. Ed25519 is a suitable choice for modern systems that support it. If an organization requires another algorithm or uses an older server, its compatibility and security policy determine the selection.
A client key identifies the user or client to the server. A server host key serves a different purpose: it lets the client check the server’s identity. Creating an SSH client key does not replace verification of the server host-key fingerprint through a trusted channel.
Before generating SSH keys, identify the authorized account, the destination server, and the approved method for registering public keys. Some organizations manage keys through an administrative portal or centralized identity service instead of allowing direct edits to an account’s authorized_keys file.
Create the pair on the client
On a workstation with OpenSSH, the following command creates an Ed25519 SSH key pair at a distinct path:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_gateway -C "gateway-access"
The comment is a label for identifying the key; it does not grant access. A strong, unique passphrase should be selected when prompted. The passphrase protects the private key file if it is copied or stolen, though it does not replace protections on the workstation itself. The OpenSSH manual describes the options and output files.
The command creates ~/.ssh/id_ed25519_gateway, the private key, and ~/.ssh/id_ed25519_gateway.pub, the public key. Choosing a new filename avoids replacing an existing identity; an overwrite prompt calls for checking the path before proceeding. The private file should be accessible only to its owner, and any approved backup should be stored securely. The private key and its passphrase must not be sent to the server administrator, pasted into a ticket, or exposed in logs.
Register the public key
The next part of the “ssh generate key” procedure is to authorize the public half for the intended account. The .pub file should be provided through the organization’s approved channel. On a conventional OpenSSH server, an administrator or authorized account holder can add its complete contents as one line in that account’s ~/.ssh/authorized_keys, without removing existing entries.
The server must accept public-key authentication, and its account and file permissions must satisfy its configuration. Managed systems may use a different key store. The correct registration location and any access restrictions should follow the system’s documented policy.
A fingerprint helps distinguish this public key from older entries. On the client, the following command displays it without exposing the private key:
ssh-keygen -lf ~/.ssh/id_ed25519_gateway.pub
The fingerprint can be compared through an approved channel when the administrator registers the key. It is the client public-key fingerprint, not the server host-key fingerprint.
Verify access before removing the old key
After verification of the server identity, a separate session can use the new identity and the authorized account:
ssh -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -o PasswordAuthentication=no -i ~/.ssh/id_ed25519_gateway [email protected]
The example account and host must be replaced with the approved destination. Successful authentication with the specified identity confirms that the new client key is accepted; the private-key passphrase may still be requested locally. If login fails, the account, registered public key, permissions, server policy, and client diagnostics should be checked before changing access.
Generating an SSH client key is only complete operationally when the replacement works. The existing session or recovery route should remain available until the new login is independently verified. The old public key can then be removed from the appropriate authorization store, with a check that only the intended entry is retired.