It’s 9:00 AM. You open your terminal, ready to push code to your company’s GitLab. You type `git push`, but the system returns "Permission denied (publickey)." You check—your keys haven't changed, and your configuration remains untouched. So, what’s the problem?
The reason is simple: your `~/.ssh` directory holds three different keys—one for your personal GitHub, one for the company GitLab, and one for a server in Singapore—yet the SSH client defaults to trying only `id_rsa`. When you try to connect to the Singapore server, the client pulls out the GitHub key; naturally, it fails to unlock the door.
This isn't an isolated incident. With the rise of remote work and cross-border operations, managing multiple overseas servers from a single laptop has become commonplace. As a data center hub for the Asia-Pacific region, Singapore hosts the Southeast Asian operational nodes for many teams. If you are simultaneously managing servers in locations like Singapore, Hong Kong, and Japan, key management chaos is almost inevitable.
The core solution boils down to one simple strategy: generate a unique key for each server and use the `~/.ssh/config` file to instruct the SSH client on which key to use for which connection.
Step 1: Generate unique key pairs locally
Do not reuse keys. Generate a dedicated key pair for every server you need to manage.
Take the Singapore server as an example:
ssh-keygen -t ed25519 -C "sg-server" -f ~/.ssh/sg_server
The `-f` flag specifies the output filename, preventing you from overwriting the default `id_rsa`. The `-C` flag adds a comment—write a description that helps you remember the key's purpose, such as "Singapore web server."
Regarding the algorithm, prioritize Ed25519. It uses a fixed 256-bit length and offers encryption strength equivalent to RSA 4096, yet features smaller key sizes and better performance; it is fully supported by OpenSSH version 6.5 and later. If the target server runs an older system or a specific cloud provider only accepts RSA, use RSA with a minimum of 3072 bits—ideally 4096 bits.
During generation, the system will prompt you to enter a passphrase. Be sure to set one. This layer of password protection secures your private key file itself; should your laptop be lost or accessed by others, the private key cannot be used without the passphrase.
Step 2: Deploy the public key to the Singapore server
Once the public key is generated, it needs to be appended to the server's `~/.ssh/authorized_keys` file.
The easiest method is using `ssh-copy-id`:
ssh-copy-id -i ~/.ssh/sg_server.pub user@sg-server-ip
This command appends the public key without overwriting existing entries. This means the server can store multiple public keys simultaneously—keys from your own laptop, a colleague's operations machine, and a CI/CD system can all coexist in the same `authorized_keys` file.
If you are setting up a brand-new Singapore server, you must log in using a password for the initial connection. Only after deploying the public key and confirming that key-based login works should you modify `/etc/ssh/sshd_config` to set `PasswordAuthentication no`. Do not reverse this order; otherwise, a misconfiguration could lock you out of the server.
Permissions for `authorized_keys` must be set to `600`, and the `.ssh` directory to `700`. If permissions are incorrect, SSH will reject the key—this is the most common reason why login fails even though the key has been successfully uploaded.
Step 3: Enable "one-click switching" using the config file
This step is the core of the entire solution. Open `~/.ssh/config` (create it if it doesn't exist) and write a configuration block for each server:
Host sg-web
HostName [Your Singapore Server IP]
User deploy
IdentityFile ~/.ssh/sg_server
IdentitiesOnly yes
`Host` is an alias of your choice; you can name it whatever you like, and subsequently connect using `ssh sg-web`. Enter the actual IP address for `HostName`, and point `IdentityFile` to the corresponding private key file.
The `IdentitiesOnly yes` line warrants a specific explanation. By default, if multiple keys are loaded into the SSH Agent, the client will attempt them one by one until a server accepts one. This leads to two issues: first, connection speeds slow down because the system attempts multiple keys via trial and error; second, you might trigger the server's "maximum authentication attempts" limit, resulting in an immediate disconnection. By adding `IdentitiesOnly yes`, SSH will use only the specific key you designated and ignore any other identity files.
If you manage more than just one Singapore server—for instance, one for a database and another for object storage—you can simply add more entries to your config file:
Host sg-db
HostName 10.0.1.5
User admin
IdentityFile ~/.ssh/sg_db
IdentitiesOnly yes
Host sg-storage
HostName 10.0.2.8
User ops
IdentityFile ~/.ssh/sg_storage
IdentitiesOnly yes
With this setup, running `ssh sg-web`, `ssh sg-db`, or `ssh sg-storage` will use the respective keys without interference. You can also combine this with `ProxyJump` to allow internal network machines to connect via a jump host—a highly practical approach for managing cross-region server clusters.
Common Pitfalls
Duplicate keys. Running `ssh-copy-id` multiple times with the same public key creates duplicate entries in `authorized_keys`; while this doesn't break functionality, it creates clutter. It is best to use `sort -u` to remove duplicates or clean up the file manually.
Private key permissions. Private key files must have `600` permissions (readable only by the owner). If you copy a private key from one machine to another, remember to manually run `chmod 600`.
Deployment order. When bringing a new server online, log in with a password first, deploy the public key, verify that key-based authentication works, and *then* disable password authentication. If you disable password authentication before verifying the key, you risk losing access entirely if there is an issue with the key.
Regular audits. Periodically check the `authorized_keys` files on your servers. Promptly remove public keys belonging to employees who have left or projects that have ended to prevent security risks where access remains active after personnel changes. Jtti’s Singapore VPS offerings support SSH key authentication by default; users can generate key pairs via the control panel or manually configure `authorized_keys` directly on the server. For teams looking to deploy services in Southeast Asia, the first step toward standardized key management is selecting a server that allows for configuration according to your own security standards.
Jtti’s Singapore VPS supports the flexible configuration of multiple SSH public keys. Coupled with dedicated CN2 GIA return routes, this ensures low latency and high stability for access from mainland China. Whether you use `ssh-copy-id` for rapid deployment or manage keys precisely via configuration files, the reliability of the underlying network is just as crucial as the standardization of the key system—after all, no matter how many keys you have, the path beyond the door must be a steady one.
EN
CN