October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Manage Multiple SSH Keys for Git on Linux

A practical Linux guide to separating work and personal Git identities with SSH aliases, explicit key selection, ssh-agent, and repository-specific fallbacks.
Length8 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use one SSH key pair for each Git identity, give each identity its own host alias in ~/.ssh/config, and point every repository at the matching alias. Set IdentitiesOnly yes so OpenSSH does not guess among unrelated keys. An SSH agent is optional, but ssh-add makes passphrase-protected keys convenient to use.

This arrangement cleanly separates, for example, a company account from a personal account even when both accounts use the same Git host.

As an Amazon Associate I earn from qualifying purchases.

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

The setup you are building

SSH normally sees a hostname such as github.com. If two accounts on that service require different keys, a plain remote such as [email protected]:team/project.git does not tell SSH which identity to select. Host aliases solve that ambiguity: each alias keeps the real hostname but maps to a different private key.

  • Work identity: alias github.com-work, key ~/.ssh/id_ed25519_work
  • Personal identity: alias github.com-personal, key ~/.ssh/id_ed25519_personal
  • Repository remote: uses the alias as its hostname, not the literal github.com

The alias affects only SSH connection selection. The Git service still receives a normal connection to its real host because HostName remains github.com.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Before configuring SSH

Decide which identities you need

Use a separate key pair for every account or trust boundary. A work account, personal account, client account, and deployment identity should not share a private key. Clear filenames make later auditing and rotation possible.

Check your OpenSSH version and existing files

Run ssh -V and inspect your current configuration with sed -n '1,240p' ~/.ssh/config if the file exists. OpenSSH versions and Linux distributions differ in their default identity-file list. The Debian bookworm manual lists ~/.ssh/id_ed25519 among the defaults; newer Debian documentation also lists ~/.ssh/id_mldsa44_ed25519. Do not rely on a default filename when accounts need strict separation. Verify the installed behavior with man ssh_config.

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

Protect the SSH directory

Create the directory and apply conventional permissions before generating keys:

mkdir -p ~/.ssh
chmod 700 ~/.ssh

SSH may reject a private key or configuration that is writable by other users. After creating files, use chmod 600 for private keys and chmod 644 for corresponding public keys.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Create one key pair per Git identity

Generate the work key

  1. Run ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work -C "git-work".
  2. When prompted, enter a strong passphrase. The private key is saved as ~/.ssh/id_ed25519_work; the public key is ~/.ssh/id_ed25519_work.pub.
  3. Confirm the permissions: chmod 600 ~/.ssh/id_ed25519_work and chmod 644 ~/.ssh/id_ed25519_work.pub.

Generate the personal key

  1. Run ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_personal -C "git-personal".
  2. Use a different passphrase if that helps you distinguish the identities, or use the same high-quality passphrase if your policy permits it.
  3. Apply chmod 600 ~/.ssh/id_ed25519_personal and chmod 644 ~/.ssh/id_ed25519_personal.pub.

The comment supplied with -C is only a label; it does not authenticate you and can be changed without changing the key.

Register each public key with the correct account

Display a public key with cat ~/.ssh/id_ed25519_work.pub or cat ~/.ssh/id_ed25519_personal.pub, then add it to the SSH-key area of the matching Git account. Upload only the .pub file contents. Never upload or paste a private key, whose filename has no .pub suffix.

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.

Build ~/.ssh/config with host aliases

Create or edit ~/.ssh/config:

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

What each directive does

  • Host github.com-work and Host github.com-personal define names that you will use in Git remotes.
  • HostName github.com tells SSH where to connect after an alias is selected.
  • User git is the SSH username used by this Git-hosting pattern; the account identity comes from the registered key.
  • IdentityFile names the private key for that alias.
  • IdentitiesOnly yes restricts authentication to the configured identity and certificate files, even if an agent has other keys loaded. Its default is no.
  • AddKeysToAgent yes asks the agent to load a key when it is first used. It does not replace IdentitiesOnly and does not itself choose which key is valid.

Keep the wildcard block limited to genuinely global settings. OpenSSH reads command-line options first, then the user configuration, then the system configuration; for most directives, the first value obtained is used. A generic IdentityFile placed in Host * can therefore take precedence over a later alias block. The example avoids that problem by putting identity files only in the alias blocks.

Multiple IdentityFile lines

Repeating IdentityFile adds identities to the list tried in sequence; it does not replace an earlier value. That behavior is useful when one alias legitimately has several authorized keys, but it is usually the wrong choice for two separate accounts. Give each account its own alias instead.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Optional file organization

For a larger setup, you can split entries into files and include them:

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

Include accepts glob wildcards and ~; relative user paths resolve below ~/.ssh. A Match block applies declarations only until the next Host or Match line, so keep conditional rules narrowly scoped.

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

Load keys in ssh-agent (optional)

You can use passphrase-protected keys without an agent, but you will be prompted whenever SSH needs an unloaded key. Start an agent in the current shell with:

eval "$(ssh-agent -s)"

Then add the keys explicitly:

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

List loaded identities with:

ssh-add -l

If you enabled AddKeysToAgent yes, the first connection using an alias can load that key automatically. Explicit ssh-add is still useful when you want to enter passphrases before starting Git work or when diagnosing which keys are available. Because an agent may contain unrelated keys, keep IdentitiesOnly yes in every identity-specific block.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Point each repository at the right alias

Clone a new repository

Use the alias in the SSH URL:

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

For a personal account on the same service:

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

The text before the colon is parsed as the SSH host. Replacing github.com with the alias is what activates the corresponding configuration block.

Change an existing clone

Inspect the current remotes:

git remote -v

Change the fetch-and-push URL together with:

git remote set-url origin [email protected]:your-org/repo.git

Verify the result with git remote -v. If the repository has a separate push URL, inspect it with git remote get-url --all origin and update it explicitly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git remote set-url --push origin [email protected]:your-org/repo.git

Git stores the remote in .git/config. Editing that file directly is equivalent, but git remote set-url reduces syntax mistakes.

Test selection before pushing

Ask SSH which configuration it will use

Use the fully qualified alias with:

ssh -G [email protected]

Review the resulting values for hostname, user, identityfile, and identitiesonly. Repeat with the personal alias. This checks configuration expansion without attempting authentication.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Trace an authentication attempt

Run a verbose test:

ssh -vT [email protected]

The trace shows which configuration files were read, which identity files were offered, and whether the server accepted a key. Output and greeting text vary by provider, and Git hosting normally does not provide an interactive shell; use the authentication result rather than expecting a particular sentence. Test the personal alias separately.

Make a harmless Git request

After SSH authentication succeeds, run git ls-remote origin inside the repository. It checks that the remote alias, account authorization, and repository path work together without creating a commit or changing files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose aliases or a per-repository command

Host aliases are the general solution, but a repository-local SSH command can be preferable when only one clone needs an exceptional key.

Approach Configuration Scope Trade-off
Host aliases Entries in ~/.ssh/config; remotes use names such as github.com-work Every repository whose remote uses the alias Centralized and predictable; every remote must use the correct alias
Per-repository core.sshCommand git config core.sshCommand "ssh -i ~/.ssh/id_ed25519_work -o IdentitiesOnly=yes" Only the current repository, stored in .git/config No alias is needed, but each clone must be configured and maintained separately
Agent order alone Load several keys and rely on the order offered Any connection using that agent Implicit and fragile; an agent can offer an unintended key or hit server attempt limits

The per-repository command is useful for a one-off checkout, a deployment repository, or a project whose remote URL cannot be changed. Include -o IdentitiesOnly=yes so the command does not fall back to other agent identities. To set it only for the current repository, run the command from that repository without --global.

Troubleshoot the common failure modes

Symptom Likely cause Fix
The wrong account is used The remote still contains github.com, or it uses the other alias Run git remote -v and replace the hostname with the intended alias using git remote set-url.
SSH offers several unexpected keys IdentitiesOnly yes is missing, or the alias is not being matched Confirm the remote hostname, run ssh -G, and add IdentitiesOnly yes to the matching block.
Permission denied (publickey) The public key is not registered to that account, the wrong private file is named, or the agent has not loaded a passphrase-protected key Check the alias with ssh -G, run ssh-add -l, add the intended key, and verify that the corresponding .pub key is attached to the correct account.
Changes work for fetch but not push A separate push URL points to another host or alias Inspect git remote get-url --all origin and set the push URL explicitly.
Configuration changes appear ignored An earlier declaration supplied the value, or the file has a syntax/permission problem Check ordering, remembering that the first value found usually wins; run ssh -G and inspect verbose output with ssh -vT.
The key is rejected before authentication Private-key or ~/.ssh permissions are too broad Use chmod 700 ~/.ssh, chmod 600 ~/.ssh/id_ed25519_work, and the equivalent mode for every private key.
A copied configuration works on one machine but not another The second machine has different OpenSSH defaults or missing key files Copy keys through a secure method, check paths, and consult that machine’s man ssh_config for version-specific defaults.

Security and maintenance practices

  • Keep private keys readable only by your account and never commit them to a repository, paste them into an issue, or send them through chat.
  • Use a passphrase and let the agent retain the unlocked key for the session instead of storing an unencrypted private key.
  • Record which alias belongs to which account. The filename and comment are labels, while the Git service’s registered public key determines authorization.
  • When a device is lost or an employee leaves, remove that key from the Git account immediately and create a replacement pair rather than reusing a shared private key.
  • Review ssh-add -l when troubleshooting and remove an unnecessary loaded key with ssh-add -d ~/.ssh/id_ed25519_personal.
  • Back up private keys only in an encrypted, access-controlled location. A public key can be regenerated from a private key, but not the reverse.

A repeatable checklist

  1. Create a uniquely named Ed25519 key pair for each Git identity.
  2. Register each public key with the matching account.
  3. Add one alias block per identity in ~/.ssh/config, including HostName, User, IdentityFile, and IdentitiesOnly yes.
  4. Start ssh-agent when needed and load keys with ssh-add, or rely on AddKeysToAgent yes for first-use loading.
  5. Set every repository remote to the correct alias hostname.
  6. Use ssh -G, ssh -vT, and git ls-remote to verify selection and authorization.
  7. If aliases are unsuitable for one repository, set a repository-local core.sshCommand with an explicit identity and IdentitiesOnly=yes.

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.