How to Share SSH Keys and Private Keys Safely
Published by Paste & Purge · Engineering Best Practices · 9 min read
Secure Shell (SSH) is the standard protocol for managing remote Linux servers, executing automated deployment pipelines, and authenticating with Git code repositories. Authentication relies on asymmetric cryptographic key pairs: a public key and a private key.
A private key can authenticate as whichever user or service the server authorizes; it does not automatically grant root privileges. Exposing private key material can nevertheless allow unauthorized access and requires careful revocation.
Public Key (.pub)
Safe to share openly. Placed on destination servers in ~/.ssh/authorized_keys to verify incoming connections.
Private Key (No extension)
Extremely sensitive cryptographic secret. Proves identity to the server. Should never be shared when an alternative workflow is possible.
Grant SSH access without passing private keys
- Verify the person's identity and approve the required host, account, privileges, and access end date.
- Have each user create and protect their own private key. Collect only their public key, then authorize it through the host or identity system.
- Use a separate named account or managed short-lived SSH access where supported. Avoid shared root logins and shared deploy-key private material.
- At offboarding, remove their authorization, review other access paths and sessions, and rotate any genuinely shared keys that could remain in their possession.
GitHub's SSH documentation distinguishes private keys kept on a device from public keys registered for authentication. Server-specific onboarding and revocation depend on your platform.
The Golden Rule: Provision a New Key Instead of Sharing a Private Key
In standard engineering workflows, you should rarely need to send a private key to another person. The industry-standard approach is:
- Have the recipient generate their own key pair locally:
ssh-keygen -t ed25519 -C "developer@company.com" - The recipient transmits only their public key (
id_ed25519.pub) to you. - You append their public key to the target server's
authorized_keysfile. - When access ends, remove that key from every applicable authorization location and review other credentials or access mechanisms the person may have used.
When Private Key Transmission Might Occur
While provisioning individual keys is the gold standard, specific operational scenarios sometimes require temporary transmission of private cryptographic material:
Shared CI/CD Service Account Deploy Keys
Transferring an automated build deploy key to a new deployment runner or air-gapped server environment.
Server Migration & Host Key Transfers
Migrating legacy servers where preserving existing SSH host keys is necessary to avoid host key fingerprint mismatch warnings.
Client-Supplied Staging Certificates & Keys
A client providing a dedicated temporary access certificate for an isolated staging environment during a time-sensitive emergency.
Safe Handling Checklist for Private Keys
1. Always Encrypt with a Passphrase
Never use unencrypted private keys. If a private key lacks a passphrase, add one before sharing using: ssh-keygen -p -f ~/.ssh/id_ed25519.
2. Enforce Strict Permissions (chmod 600)
Once downloaded, the recipient must lock down file permissions: chmod 600 ~/.ssh/id_ed25519 and chmod 700 ~/.ssh.
3. Use One-Time Client-Side Encrypted Transmission
Never paste private key blocks into Slack, Jira, or email. Transmit via a single-view, client-side encrypted Paste & Purge link with a secondary passphrase.
Critical Mistakes to Avoid
- ✕Never commit private keys or .pem files to Git repositories (even private repos).
- ✕Never paste private keys into unencrypted helpdesk tickets or project management cards.
- ✕Do not share personal developer private keys; provision distinct keys for each engineer.
- ✕Never assume deleting a secret link revokes server access; always manage authorized_keys.
Frequently Asked Questions
Transmit Developer Secrets Without Plaintext Traces
Create client-side encrypted, 1-view secret links for temporary tokens, configurations, and sensitive key material. Keep your chat logs and email archives clean.