DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk9 min

How to Manage Multiple SSH Keys for Git on Linux

Use one key pair per Git identity, map each key to an SSH host alias, and point repository remotes at the matching alias. This Linux guide covers key creation, ssh-agent, verification, troubleshooting and the per-repository alternative.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reliable pattern is one SSH key pair per identity, one host alias per key in ~/.ssh/config, and Git remotes that use the matching alias. Set IdentitiesOnly yes in each alias so OpenSSH does not offer an unrelated agent key, then load keys with ssh-agent only if you want passphrase caching.

Why separate SSH keys for Git identities

SSH authentication identifies a key, not a Git repository. If your personal and work accounts use the same key, the server can authenticate the key but cannot distinguish which identity you intended. A separate key pair for each identity gives you a clear boundary: you can remove a departing employer’s key without changing your personal access, and you can see which account a connection is supposed to use.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The hostname creates the routing problem. A typical Git URL uses [email protected]:owner/repository.git. Two accounts on the same service therefore appear to use the same SSH destination. OpenSSH solves that by letting you create local aliases such as github.com-work and github.com-personal. Both aliases point to the real host, but each selects a different private key.

The configuration pattern at a glance

Purpose Setting or action What it controls
Identity separation One key pair per account or organisation Which public key is registered on the remote service
Routing A distinct Host alias in ~/.ssh/config Which key OpenSSH selects when Git connects
Predictability IdentitiesOnly yes Prevents other agent-held identities from being tried
Repository selection Remote URL containing the alias hostname Which SSH configuration block a clone or fetch uses
Passphrase convenience ssh-agent and ssh-add Whether private keys must be unlocked on every connection

An alias is local syntax; it does not create a DNS name. The HostName directive sends the connection to the actual service hostname.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Prepare clearly named key pairs

Choose a file name that describes the identity

Use names such as ~/.ssh/id_ed25519_work and ~/.ssh/id_ed25519_personal. The private key has no filename requirement, but descriptive names prevent you from accidentally registering or loading the wrong key. Keep the public-key companion, ending in .pub, beside it.

OpenSSH versions have different default identity-file lists. A Debian bookworm ssh_config(5) page lists ~/.ssh/id_ed25519 among the defaults, while a newer Debian listing also includes ~/.ssh/id_mldsa44_ed25519. Do not rely on an implicit default when several identities exist; specify each file explicitly and check man ssh_config on the Linux installation you are using.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a key for each identity

Ed25519 is a practical modern choice on systems that support it. Generate each key separately and protect every private key with a passphrase:

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work -C "work Git identity"
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_personal -C "personal Git identity"

The comment is metadata for your own identification; it does not grant access. The private files must remain readable only by you. If the command creates the directory for the first time, confirm that ~/.ssh is private and that the key files are not shared through backups or dot-file repositories without encryption.

Register the public keys with the correct accounts

Copy the contents of each .pub file into the SSH-key area of the corresponding Git service account or organisation. Register id_ed25519_work.pub only with the work identity and the personal file only with the personal identity. Never upload a private key or paste its contents into a web form. If an organisation labels keys, use labels that include the machine and identity, for example “laptop-work”.

Build ~/.ssh/config with one alias per key

Create or edit ~/.ssh/config. The following pattern maps two local aliases to the same real host:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Host *
  AddKeysToAgent yes

Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes

Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal
  IdentitiesOnly yes

User git is the SSH login name used by many Git hosting services; use the service’s documented SSH user if yours differs. The alias text can be any unused name, but keeping the real host plus an identity suffix makes Git URLs easy to recognise.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Why IdentitiesOnly yes matters

OpenSSH’s default for IdentitiesOnly is no. With that default, an agent can offer additional keys beyond the file named in the host block. A server may reject the connection after too many incorrect offers, or it may authenticate the wrong account first. Setting IdentitiesOnly yes tells SSH to use only the configured identity and certificate files for that host, even when the agent contains other keys. This makes the alias deterministic.

Do not confuse this with AddKeysToAgent yes. The latter asks SSH to add a key to the agent after the key is used; it does not limit which identities the agent may offer. Keep both directives when you want automatic loading and strict identity selection.

Understand repeated IdentityFile lines

Repeating IdentityFile adds files to the identities tried in sequence; it does not replace an earlier value. That behaviour is useful when a host legitimately accepts more than one key, but it is usually the wrong choice for separate personal and work accounts. Give each alias one intended key unless you have a specific fallback requirement.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the correct remote URL for every repository

Clone new repositories

Replace the normal hostname with the alias. For the work identity, a clone command looks like:

git clone [email protected]:your-org/repo.git

For a personal repository, use the personal alias:

git clone [email protected]:your-user/repo.git

Everything after the colon remains the service’s repository path. Git passes the alias to SSH as the destination host, so OpenSSH selects the matching Host block and then connects to the HostName value.

Change an existing clone

An existing checkout keeps whatever hostname was recorded when it was cloned. Inspect it first:

git remote -v

Change only the remote URL, choosing the alias that matches the repository’s account:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
git remote set-url origin [email protected]:your-org/repo.git
git remote -v

The second command confirms that fetch and push now display the alias. The repository’s .git/config stores this value; changing one checkout does not alter any other repository on the machine.

Use ssh-agent when passphrase caching is useful

Start an agent in the current shell

If no desktop session or distribution service has already started one, launch an agent and import its environment:

eval "$(ssh-agent -s)"

This command affects the current shell. A new terminal may need the agent environment again unless your desktop, login manager, or shell startup already provides it.

Add and inspect keys

ssh-add ~/.ssh/id_ed25519_work
ssh-add ~/.ssh/id_ed25519_personal
ssh-add -l

ssh-add -l lists fingerprints for keys currently loaded. It does not prove that a repository uses a particular key; the host alias and IdentitiesOnly setting still determine what SSH offers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

With AddKeysToAgent yes, the first use of a configured key can load it into the agent after you enter its passphrase. You can also add keys explicitly with ssh-add. These are separate choices: automatic loading controls convenience, while IdentitiesOnly controls selection.

Verify identity selection before pushing

Ask SSH which effective configuration it will use

OpenSSH can print the options resulting from all configuration files and command-line settings:

ssh -G github.com-work

Check that the output contains the expected hostname github.com, user git, the work identityfile, and identitiesonly yes. Repeat with the personal alias. This catches spelling errors in aliases and paths before Git is involved.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Test authentication without opening a shell

ssh -T [email protected]
ssh -T [email protected]

Git hosting services commonly respond with an account greeting and explain that interactive shell access is unavailable. The exact wording is service- and account-dependent, so use the account name shown by the service as the check rather than expecting one fixed sentence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Trace a failed connection

Add verbose output when the test does not identify the expected account:

ssh -vT [email protected]

Look for the configuration file and host block being read, the identity file offered, and whether the agent contributes another key. If the wrong key appears, verify the alias spelling, the IdentityFile path, and IdentitiesOnly yes. If the right key is offered but rejected, check that its matching public key is registered on the intended account and that file permissions allow SSH to read the private key safely.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Alternative: select a key per repository with core.sshCommand

A repository can specify its own SSH command instead of using host aliases. Set it from inside that checkout:

git config core.sshCommand "ssh -i ~/.ssh/id_ed25519_work"

Git writes the setting under [core] in that repository’s .git/config. This approach is useful when only one repository needs an exceptional key or when you cannot change the remote URL. It applies only to that repository, so every additional checkout requires its own setting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach Strength Trade-off
Host aliases One central mapping works for all repositories that use the alias Remote URLs must contain the alias hostname
core.sshCommand No alias is required; selection is local to one repository Each checkout must be configured and maintained separately
Relying on agent order Little configuration initially Selection is implicit and can change as keys are added or reordered

For multiple identities on the same Git host, aliases plus IdentitiesOnly yes are generally easier to audit. Use a per-repository command when the exception genuinely belongs to one checkout.

Configuration scope, ordering and reusable files

OpenSSH evaluates command-line options first, then the user file ~/.ssh/config, then the system configuration. For most directives, the first value found is used. Put broad defaults before specific host blocks, and avoid a broad setting that unintentionally supplies an identity to every host.

Include can load additional configuration files using glob wildcards and ~. Relative user paths resolve under ~/.ssh. A modular layout might keep work entries in ~/.ssh/config.d/work.conf and include them from the main file:

Include ~/.ssh/config.d/*.conf

Match limits following declarations until the next Host or Match. Because conditional blocks can change which options apply, inspect the effective result with ssh -G alias after editing them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common failure modes and fixes

Git still uses the original hostname

If git remote -v shows [email protected]:... rather than an alias, the repository never reaches your identity-specific host block. Run git remote set-url with the correct alias, then verify the remote again.

The server authenticates the wrong account

Confirm that the alias points to the intended private key and that IdentitiesOnly yes is inside that alias block. Remove accidental duplicate IdentityFile lines, inspect loaded keys with ssh-add -l, and repeat the verbose test.

“Too many authentication failures” appears

An agent holding many keys may offer them before the server accepts one. The per-alias IdentitiesOnly yes setting limits offers to the configured identity. If you use core.sshCommand, add the option explicitly:

git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_work"

SSH says the private key permissions are too open

Restrict the directory and private files, then retry:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519_work ~/.ssh/id_ed25519_personal
chmod 644 ~/.ssh/id_ed25519_work.pub ~/.ssh/id_ed25519_personal.pub

Use the ownership and permission conventions required by your distribution. Do not loosen permissions on a private key to work around an error.

The configuration change appears to do nothing

  • Check that the file is exactly ~/.ssh/config, not a similarly named file.
  • Ensure each directive is indented consistently and that the alias in the Git URL exactly matches the Host line.
  • Run ssh -G alias to see the effective values rather than guessing which block won.
  • Use ssh -vT to distinguish configuration errors from a missing or unregistered public key.

Maintenance and security checklist

  • Keep one private key per identity and label files unambiguously.
  • Back up encrypted private keys, never plaintext copies in a public repository.
  • Remove a key from the remote account and local agent when the identity or device should no longer have access.
  • Review ~/.ssh/config after changing distributions or OpenSSH versions because default identity-file lists can change.
  • Use aliases consistently in scripts, CI jobs and documentation so a repository cannot silently fall back to the wrong hostname.
  • Regenerate a compromised key and register its replacement; changing a filename alone does not revoke the old public key.

A repeatable setup sequence

  1. Create a uniquely named key pair for each Git identity.
  2. Register only each public key with its matching account.
  3. Add one Host alias per identity in ~/.ssh/config, including HostName, User, IdentityFile and IdentitiesOnly yes.
  4. Optionally enable AddKeysToAgent yes, start ssh-agent, and load keys with ssh-add.
  5. Clone with the alias hostname or update an existing repository’s origin URL.
  6. Run ssh -G and ssh -T for each alias before the first push.
  7. If a repository needs an isolated exception, set its core.sshCommand instead of adding another global alias.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.