DEV Community

webit
webit

Posted on

TIP: Dealing with multiple SSH key repositories

I have different Git repositories cloned with different SSH keys. Say, one is work code and one is personal / side project.
When I finish work on one repository and start to work on the another and want to fetch the latest changes, I have to switch SSH keys.

That is sometimes annoying as I have to execute following command every time I switch from one repo to another:

ssh-add -D # delete cached key
ssh-add ~/.ssh/my-key # add key I need to use to the ssh-agent
Enter fullscreen mode Exit fullscreen mode

There are some solutions for this, like Configuring SSH
But I found it not so nice solution, although maybe they are fully automated. You have to configure hosts, clone repository with different host, etc. I prefer something else.

Shell aliases for the rescue

I created shell script aliases that will do commands listed above:

alias sshWork="ssh-add -D; ssh-add ~/.ssh/my-work-key"
alias sshPersonal="ssh-add -D; ssh-add ~/.ssh/my-personal-key"
Enter fullscreen mode Exit fullscreen mode

Now, all I need to is to execute either sshWork or sshPersonal command and it will delete previously cached key + add new identity to the authentication agent.

It's that simple.

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (1)

Collapse
 
ccoveille profile image
Christophe Colombier

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay