DEV Community

Cover image for Managing Multiple SSH Keys & Git Profiles with xks
rwx222
rwx222

Posted on β€’ Edited on

Managing Multiple SSH Keys & Git Profiles with xks

If you've ever been in a situation where your company requires you to use a different GitHub account from your personal one (or GitLab, Bitbucket, etc), with a corporate email.

Or if you need to use different SSH keys to access various remote servers.

Then you've likely faced the tedious task of manually managing multiple accounts or profiles on the same computer, with different SSH keys and/or different Git configurations in your .gitconfig file.

There are both simple and advanced ways to handle this with special Git and SSH configurations, but honestly, I just wanted a quick and simple way to switch between profiles without overcomplicating things.

That's why I created xks.


What is xks?

xks is a CLI written in Rust to switch SSH keys and/or Git profiles with a single command.

It works without extra configurations, using (and only considering) the default files in Unix systems (Linux & macOS):

Git File

~/.gitconfig
Enter fullscreen mode Exit fullscreen mode

SSH Files

~/.ssh/config

~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub

~/.ssh/id_ecdsa
~/.ssh/id_ecdsa.pub

~/.ssh/id_rsa
~/.ssh/id_rsa.pub

~/.ssh/id_dsa
~/.ssh/id_dsa.pub
Enter fullscreen mode Exit fullscreen mode

(Only the files that exist when saving a profile; any other custom-named SSH keys are ignored).


πŸ› οΈ How Does It Work?

xks stores backups of your .gitconfig file and SSH keys in their current state inside the local ~/.xks directory as a profile.

You can then modify/delete the current files, save them as another profile, and safely switch between profiles without worrying about losing configurations.


πŸ“¦ Installation

You can install it in seconds with curl:

curl -fsSL https://xks.rwx222.com/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Or if you prefer wget:

wget -qO- https://xks.rwx222.com/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Or, if you prefer, you can check out the code and compile it yourself with Rust.

Then run:

xks help
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ Commands

  • xks List saved profiles and current files state.
  • xks save <profile> Save the current files as a profile.
  • xks use <profile> Apply a saved profile.
  • xks use - Switch back to the previously used profile.
  • xks remove <profile> Delete a saved profile ⚠️.
  • xks discard Delete the current files ⚠️.

πŸ€” Why Not Use Another Tool?

As I mentioned, I know there are other ways to handle this situation. But they all require extra manual configurations.

xks simply switches everything with one command and leaves it as if you had never changed anything.


πŸš€ Try It and Let Me Know What You Think

If you have feedback, improvements, or find a bug, PRs are welcome.

πŸ’» GitHub Repo

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly β€” using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

If you found this post useful, please drop a ❀️ or leave a kind comment!

Okay