Best practice for managing SSH keys across multiple GitHub repositories? #203471
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaOther Discussion DetailsI'm using GitHub Actions to deploy multiple applications to the same VPS/cPanel server over SSH. Currently, each repository has its own private key stored as a GitHub Secret, even though they all deploy to the same server. I'm wondering what the community considers the best practice here. Questions:
I'd love to hear how others handle this in production. |
Replies: 1 comment
SSH Key Management for Multi-Repo Deployments to a Shared ServerOne key per repo vs. one shared keyBest practice: one dedicated key pair per repository (or per deployment pipeline). Reusing a single key across multiple repos is convenient, but it creates a "blast radius" problem — if one repo's secret leaks (compromised Action, malicious PR from a fork, leaked log, etc.), the attacker gets SSH access to every app on that server, not just the one that leaked. Since you're deploying to a shared VPS anyway, that's the scenario you most want to avoid. So the general recommendation is:
Scoping keys instead of just trusting isolationJust having separate keys isn't enough if every key still has full shell access as the same deploy user. On the server side ( This means even if If your cPanel setup makes editing
Maintainability trade-offThe honest trade-off: yes, N repos means N key pairs to manage instead of 1. In practice this is manageable because:
Rotating keys without breaking deploymentsThe safe rotation pattern is overlap, don't swap:
This gives you a safety net — if step 3/4 has a typo or the new key wasn't added correctly, the old key is still there and your next deploy doesn't just hard-fail. Some teams script this rotation (a small Ansible/shell script that appends the new key and only prunes keys older than N days) so it's not a manual SSH-in-and-edit-a-file chore every time. Quick summary
|
SSH Key Management for Multi-Repo Deployments to a Shared Server
One key per repo vs. one shared key
Best practice: one dedicated key pair per repository (or per deployment pipeline).
Reusing a single key across multiple repos is convenient, but it creates a "blast radius" problem — if one repo's secret leaks (compromised Action, malicious PR from a fork, leaked log, etc.), the attacker gets SSH access to every app on that server, not just the one that leaked. Since you're deploying to a shared VPS anyway, that's the scenario you most want to avoid.
So the general recommendation is:
ed25519key pair per repo.