July 12, 2026 · Docker HQ Team

How to Protect SSH Keys on a Mobile Device

To protect SSH keys on a mobile device, store the private key in hardware-backed storage (the Secure Enclave on iOS or the Android Keystore / StrongBox), require biometric or PIN unlock before every use, and give each key a strong passphrase. Never keep a private key in a Notes app, a synced folder, or a plain file in your Downloads directory. Use one key per host so a single lost device doesn't hand an attacker your whole fleet.

A phone is a different threat model than a laptop. It gets left on tables, handed to kids, and lifted off café chairs, and it syncs half its contents to a cloud account you barely think about. If you SSH into production from your phone, the private key on that device is a real credential. It can start and stop containers, read logs, and open a root shell. Treat it that way.

To protect SSH keys on mobile, storage is the biggest decision

Where the private key is stored matters more than anything else you'll configure. There are three tiers, worst to best.

Plain file (avoid). A file like ~/.ssh/id_ed25519 on the device filesystem, or worse, a key pasted into a note or a cloud drive. Anything that reads the filesystem or restores a backup can lift it. iCloud and Google Drive backups will happily carry that file to another device.

Encrypted file with a passphrase (acceptable). The key file is encrypted at rest and useless without the passphrase. Better, but the decrypted key still passes through app memory, and a weak passphrase is brute-forceable offline once the file is stolen.

Hardware-backed key (best). The private key is generated inside the phone's secure hardware and never leaves it. Your app asks the hardware to sign the SSH challenge; the raw key bytes are not readable by the OS, the app, or a backup. This is the Secure Enclave on iPhone and the Keystore (ideally StrongBox) on Android.

If your SSH client supports hardware-backed keys, use them. It kills the entire class of "someone copied my key file" attacks.

Generate the right kind of key

Use Ed25519. It's fast, keys are short, and there are no RSA bit-size footguns to get wrong.

ssh-keygen -t ed25519 -C "phone-prod-web-01" -f ~/.ssh/id_ed25519_prod

Set a passphrase when prompted. A passphrase-less key is a plaintext credential the moment the file leaves the device. Make the comment (-C) say what the key is for so you can revoke the right one later.

If you generate the key on a laptop and move it to the phone, copy only the public key to the server and import the private key into a client that will encrypt it. Then delete the private key from anywhere it sat in plaintext, including your shell history and any messaging app you used to move it. Better still: generate the key on the phone so the private half is born in secure storage and never travels.

Lock the key behind biometrics

Storage at rest is half the problem. The other half is unlock. A stolen, unlocked phone with an SSH app already authenticated is game over. Configure your client so that using a key requires Face ID, Touch ID, or a fingerprint every time, not just once per app launch.

Good mobile SSH clients tie the key to the device's biometric prompt. Fail the check enough times and the key becomes unusable. That's the behavior you want. If your client only asks for biometrics to open the app and then keeps keys hot in memory for hours, that's weaker than it looks.

Docker HQ keeps SSH keys in the platform keystore and gates them behind device biometrics, so opening a container shell or reading logs from your phone still needs a live Face ID or fingerprint check. Losing the phone doesn't mean losing the servers.

One key per host, and scope what it can do

Don't reuse one key across every server. If you do and you lose the phone, you either revoke one key and lock yourself out of everything at once, or you miss a host. Generate a distinct key per host (or per small group), name them clearly, and you can revoke one without touching the rest.

Revocation is just removing the public key from the server's authorized_keys:

# on the server, drop the line matching the lost key's comment
sed -i '/phone-prod-web-01/d' ~/.ssh/authorized_keys

You can also constrain what a key is allowed to do right in authorized_keys. If a phone key only ever needs to run a read-only status check, lock it to that command:

command="docker ps",no-port-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAA... phone-readonly

That key can log in and run docker ps and nothing else. No shell, no forwarding. A phone is your least-trusted device, so that kind of scoping is worth the effort on any key that doesn't need full access.

While you're in authorized_keys, this is the same discipline covered in Docker security best practices for production: least privilege applies to SSH keys exactly as it applies to container capabilities.

Turn off cloud backup for the key material

This one bites people. Phone backups sync a lot, and a private key file sitting in app storage can end up in iCloud or Google One. Hardware-backed keys are non-exportable and won't sync, which is another reason to prefer them. For any file-based key, confirm the containing app or directory is excluded from backup.

On iOS, files marked with the "no backup" attribute and items stored with kSecAttrAccessibleWhenUnlockedThisDeviceOnly don't leave the device. On Android, keys in the Keystore are device-bound by design. If you can't tell whether your client's keys are backup-excluded, assume they aren't and pick a different client.

Use SSH certificates if you manage more than a few hosts

Raw public keys in authorized_keys don't scale and they don't expire. Once you're past a handful of servers, SSH certificates are the cleaner model. You run a small certificate authority, sign short-lived certificates, and servers trust the CA instead of individual keys.

# sign a phone key that's valid for 8 hours only
ssh-keygen -s ca_key -I "alice-phone" -n deploy -V +8h id_ed25519_prod.pub

The win for mobile: a certificate that expires in hours means a stolen phone key is dead by tomorrow whether or not you noticed the theft. You never have to race to edit authorized_keys on every host. This pairs well with how you'd handle other short-lived credentials, which we get into in Docker secrets management: what actually works.

Watch for what a stolen key would touch

Protection isn't only prevention. Assume a key will eventually leak and make sure you'd notice. Server-side, keep an eye on auth logs:

journalctl -u ssh --since "1 hour ago" | grep "Accepted publickey"

That shows every successful key login with the key fingerprint. A login from an IP or at a time that doesn't match your habits is your signal to revoke. And if you can get a push notification when a host is reached or when a container you didn't touch restarts, you close the gap between compromise and response. Docker HQ sends alerts when a host or container changes state, which is often how you first learn something is off.

Running image scans on the same cadence matters too. A leaked key plus a vulnerable image is how a foothold turns into a breach. We cover the scanning side in Docker image vulnerability scanning: a practical guide.

Frequently asked questions

Is it safe to SSH into production from my phone at all?

Yes, if the key is hardware-backed, biometric-gated, and scoped. The phone becomes just another client. The risk isn't the phone itself, it's a plaintext key file on a device that's easy to lose. Fix the storage and unlock story and a phone is a reasonable admin device.

Should I use a password-based login instead of keys on mobile?

No. Passwords over SSH are weaker than keys and invite brute-force attempts against your server. Keep PasswordAuthentication no in sshd_config and use keys. A hardware-backed key behind biometrics is stronger than any password you'd type on a phone keyboard.

What do I do the moment I lose my phone?

Revoke that device's public keys from every server's authorized_keys, or if you use certificates, rotate the CA or let the short-lived certs expire. Then check auth logs for any logins after the phone went missing. This is why per-host keys and short cert lifetimes are worth setting up before you need them.

Do I still need a passphrase if the key is in the Secure Enclave?

The passphrase and the enclave protect against different things. The enclave stops the raw key from being copied. The biometric or PIN gate stops an unlocked-phone attacker from using it. For a hardware-backed key, the device unlock effectively is the passphrase. For any file-based key, always set a real passphrase on top.

Start with the one change that removes the most risk: move your private key out of any file and into hardware-backed storage, and turn on the per-use biometric prompt. If your current client can't do that, switch clients before you touch anything else.