---
title: How to Share SSH Keys Securely (and When You Shouldn't)
date: 2026-11-17
description: Sharing an SSH private key is usually the wrong move. Here's how to give someone server access properly with their own key, and how to hand over a private key safely when you really have to.
tags: ["ssh", "developers", "devops", "secrets-management", "how-to", "one-time-links"]
---

# How to Share SSH Keys Securely (and When You Shouldn't)

"Can you send me the SSH key for the server?" It's one of the most common requests in any small engineering team, and it's usually answered by pasting a private key into Slack. That key then grants access to the server to anyone who can read that conversation, for as long as the key is valid, which is usually forever.

Here's how to do it properly.

## Public keys vs private keys

An SSH key pair has two halves:

- The **public key** (`id_ed25519.pub`) is safe to share with anyone. You put it on servers to say "let the holder of the matching private key in".
- The **private key** (`id_ed25519`) is the secret. Anyone who has it can log in as you.

**You almost never need to share a private key.** You need to share access.

## The right way: everyone gets their own key

Ask the person to generate their own key pair:

```sh
ssh-keygen -t ed25519 -C "alex@example.com"
```

They send you their **public** key (`~/.ssh/id_ed25519.pub`). That's safe to send over Slack or email. You add it to the server:

```sh
# on the server, as the user they'll log in as
echo "ssh-ed25519 AAAA... alex@example.com" >> ~/.ssh/authorized_keys
```

Or from your machine, if you already have access and their public key file:

```sh
ssh-copy-id -f -i alex.pub user@server
```

Benefits:

- **Revocation is easy.** When Alex leaves, delete their line from `authorized_keys`. Nobody else is affected.
- **Logs show who logged in.** Shared keys make every login look the same.
- **No secret ever travels.** The private key never leaves Alex's laptop.

For larger teams, look at SSH certificates or your cloud provider's access tooling (for example AWS Systems Manager Session Manager, Google Cloud OS Login, or Tailscale SSH), which avoid managing `authorized_keys` by hand.

## When you really do have to share a private key

Sometimes there's no way around it: a deploy key baked into a legacy system, a vendor appliance with a single key, a break-glass key, or migrating a key to a new CI system. In that case:

### 1. Use a one-time encrypted link, not chat

Send the key file through a link that works once. With the [Dropzone CLI](https://dropzone.sh/dropzone.mjs), it's encrypted on your machine before upload:

```sh
curl -fsSO https://dropzone.sh/dropzone.mjs
node dropzone.mjs send ~/.ssh/deploy_key
```

The recipient writes it straight to disk:

```sh
node dropzone.mjs open "$LINK" -o ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
```

Or upload the file at [dropzone.sh](https://dropzone.sh) in the browser. Either way, what's left in the chat history is a link that no longer works.

### 2. Protect the key with a passphrase

A passphrase encrypts the private key on disk. If you're sharing it anyway, send the passphrase through a different channel than the key.

```sh
ssh-keygen -p -f ~/.ssh/deploy_key
```

### 3. Limit what the key can do

In `authorized_keys`, you can restrict a key to specific commands or source addresses:

```
from="203.0.113.0/24",command="/usr/local/bin/deploy",no-port-forwarding,no-pty ssh-ed25519 AAAA...
```

### 4. Plan the rotation

A key that's been shared should be replaced when it's no longer needed, or as soon as anyone who had it leaves.

## Never do this

- Commit a private key to a repository, even a private one.
- Paste a private key into Slack, Teams, email, a ticket or an AI chat.
- Reuse your personal key as a shared team key.
- Leave a shared key with no passphrase and full shell access.

---

**Related:** [How to share API keys securely](/blog/how-to-share-api-keys-securely) · [How to share .env files with your team](/blog/share-env-file-with-team)
