January 2, 2025
Jenkins vs GitHub Actions
I recently came across an interesting article by the team at Slack, where they share their experience migrating from Jenkins to GitHub Actions (GHA).
In this post, we will explore how to configure multiple GitHub accounts on the same local machine using SSH, which is useful when we work on both personal and work projects.
The idea is to use different SSH keys for each account without having to enter credentials constantly.
When we work with multiple accounts, each account should have its own SSH key. We can generate a new SSH key for the second GitHub account using the following command:
ssh-keygen -t ed25519 -C "Key for my second account"
We should choose a distinctive file name, such as id_ed25519_second_account, to avoid overwriting the existing SSH key.
Now we need to add the generated public key to our GitHub account. First, copy the public key content:
cat ~/.ssh/id_ed25519_second_account.pub
Then go to GitHub and in the Settings > SSH and GPG keys section, select New SSH Key and paste the content.
The ~/.ssh/config file allows you to manage different keys for different hosts. Edit the file:
nano ~/.ssh/config
Add the following configurations:
# Personal account (default account)
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# Secondary account (work or other projects)
Host github-testing
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_second_account
For repositories that belong to our second account, we need to update the remote URL to use the configured alias:
git remote set-url origin git@github-testing:username/repository.git
Verify that GitHub recognizes you correctly:
ssh -T git@github.com
ssh -T git@github-testing
If everything is correct, you will see a welcome message confirming successful authentication.
Once configured, you can run push or pull normally. Git will automatically use the correct key associated with the repository alias.