How to use different ssh credentials for GitHub for the same Linux user
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
No comments yet. Be the first to comment.
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

If you have multiple GitHub users, setting up ssh key can become tricky. You cannot add the same, default key to 2 users. You need to set up your machine to use different keys depending on which identity you want to use. This article will show how to set up ssh config to support additional ssh-key, along with your default key.
I assume you already have one ssh-key set up, it's working OK, and it's somehow similar to what they describe in the doc. This part of the setup will be left unchanged - you will be able to keep on using the standard domain with your standard key.
First, you need to generate an additional key and make sure it's saved under another name. You can follow this documentation:
$ ssh-keygen -t ed25519 -C "your_email@example.com" -f another-identity
Where `another identity is a file name where the new key is saved.
Add the another-identity.pub to your GitHub account, and test it with:
$ ssh -i another-identity -T git@github.com
Where -i another-identity makes ssh use the non-default key for connection. If all goes well, you will see your other profile name in the GitHub response:
$ ssh -i another-identity -T git@github.com
Hi marcin-test! You've successfully authenticated, but GitHub does not provide shell access.
With the new key in place, you can create .ssh/config and set there:
Host another-indenity.github.com
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/another-identity
Now, when you can test if this piece of configuration works:
$ ssh -T git@another-idenity.github.com
Hi marcin-test! You've successfully authenticated, but GitHub does not provide shell access.
Now, let's test our access to a private repository available only on our second user:
$ git clone git@github.com:marcin-test/test.git
Cloning into 'test'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Normal clone fails, but if we replace github.com with another-identity.github.com:
git clone git@another-idenity.github.com:marcin-test/test.git
Cloning into 'test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Now everything works as expected.
In this article, we have seen how to set up 2 identities for your GitHub projects.