How to Share API Keys, Tokens, SSH Keys and Database Credentials Securely
In short
- Never paste keys or tokens into chat, tickets, wikis or code. Those places are searchable and long-lived.
- Prefer giving each person or service their own scoped key, so it can be revoked on its own.
- When you must hand a key over, use a one-time link with a short expiry, then confirm it arrived.
- Share the public half of an SSH key, never the private one.
Contents
API keys, access tokens, SSH keys and database passwords are some of the most valuable secrets a team has. A single leaked cloud key can run up a large bill or expose customer data within minutes, and automated tools constantly scan public code and paste sites looking for them.
Yet developers share these credentials every day: with a new teammate, a contractor, a support engineer or a deployment system. This guide covers how to do that without leaving them behind in places attackers look.
Where credentials leak
Most leaks aren't clever attacks. They are credentials left in ordinary places:
- Team chat. A key pasted into a channel is visible to every member, searchable forever and copied to every device.
- Tickets and wikis. Issue trackers and documentation are shared widely, indexed, exported and often accessible to contractors.
- Source code and config files. A key committed to a repository stays in its history even after the line is deleted, and spreads to every clone and fork.
- Logs and screenshots. Debug output, terminal screenshots and screen recordings often include tokens and connection strings.
- Email. It stays in inboxes, archives and backups for years.
The common thread: these tools are built to keep and share information. A credential needs the opposite treatment.
Rule 1: give each person and system their own credential
The best way to share a key is often not to share it. Most platforms let you create several keys or tokens, each with its own name and permissions. Creating one per person, per service or per environment has big advantages:
- Least privilege. A read-only token for reporting can't delete anything.
- Easy revocation. When a contractor leaves, you revoke their key without breaking anything else.
- Clear audit trails. Logs show which key did what.
The same goes for databases: create a separate database user for each application and person, with only the rights they need, rather than handing out the administrator password.
Rule 2: when a key must change hands, use a one-time link
Sometimes a credential simply has to be handed over: a staging database password for a new teammate, a token for a contractor's integration, the recovery codes for a shared admin account. For those moments, a one-time link is the safe option.
With OneTimePass for developers, a secret can be any text: an API key, a token, a connection string, a .env snippet or a configuration block. Your browser encrypts it with AES-256-GCM before it is sent, the key stays in the link after the #, and the encrypted copy is deleted once it has been opened. Paste the link into chat or a ticket instead of the key itself: after your colleague has opened it, the link in the message is useless.
A few habits make this even safer:
- Pick a short expiry. 1 hour is usually enough when your colleague is waiting for it.
- Add a passphrase and tell it to them on a call, for production credentials.
- Ask for a quick confirmation that they opened it. If they find the link already used, assume the key was intercepted and rotate it.
- Send files securely, too. With Premium, a link can carry a file of up to 25 MB, such as a certificate or a key file, encrypted the same way.
SSH keys: share the public half only
SSH keys come in pairs. The public key (the file ending in .pub) can be shared freely: you add it to a server or service to grant access. The private key must never leave the person it belongs to.
So when someone needs access to a server, the right flow is:
- They create their own key pair on their own machine.
- They send you their public key. That is safe to send any way you like.
- You add it to the server's list of authorised keys.
- When they no longer need access, you remove that one line.
If you find yourself sending someone a private key, stop and create a new key pair for them instead.
Rule 3: keep credentials out of code
Applications need credentials too, and those shouldn't live in source code. Keep them in environment variables or a secrets manager provided by your hosting or deployment platform, and add files such as .env to your ignore list so they are never committed. Share an example file with the variable names and fake values, so new team members know what to fill in, and send the real values through a one-time link.
If a key has been committed by mistake, removing it in a new commit isn't enough: it remains in the history. Revoke and replace the key first, then clean up.
Automating it for teams
Teams that hand out credentials often can automate the process. With OneTimePass Business, scripts can create one-time links through the REST API, for example to deliver a fresh token to a new customer or to send a generated password to a new employee. Team policies can enforce a maximum expiry or require a passphrase on every link, and an activity log records what was shared.
What to do when a key has leaked
- Revoke or rotate the key immediately. Deleting the message isn't enough, because it may already have been copied.
- Check the logs of the service for activity you don't recognise since the leak.
- Update every system that used the old key with the new one.
- Find out how it leaked and fix the process, so it doesn't happen again.
Our guide on what to do after sending a password by email or chat walks through this in more detail.
Summary
Credentials are safest when each person and system has its own, scoped to what it needs. When one has to change hands, send it as a one-time link with a short expiry, never paste it into chat, tickets or code, and share only the public half of an SSH key. If a key does leak, rotate it first and ask questions later.