Configuring Multiple SSH Keys: A Guide for Azure and GitLab Workspaces
When you’re a freelancer juggling projects from different companies, it’s a good idea to have a separate SSH key for each one. Think of it as having a different house key for each friend’s place. It keeps things secure and neatly organized!
For example we will configure git ssh for
company1 — AZURE-DEVOPS
company2 — Gitlab
1 — Generate SSH Keys
Firstly, you’ll want to generate distinct SSH keys for each organization or repository.
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org" -f ~/.ssh/id_rsa_company1
ssh-keygen -t rsa -b 4096 -C "email@example.com" -f ~/.ssh/id_rsa_company2
2 — Add SSH Keys to the SSH Agent
Before you can use these keys with Git, you’ll need to add them to the SSH agent.
eval "$(ssh-agent -s)"
3 — Upload Public Keys to Git Repositories
For each organization or repository, go to the SSH key settings (on GitHub, it’s in the settings for your profile or organization) and add the corresponding public key
(e.g, id_rsa_company1.pub for azure devops repo).
(e.g, id_rsa_company2.pub for gitlab).
- Log in to your GitLab account.
- Click on your avatar at the top right, then select Settings.
- In the left sidebar, click on SSH Keys.
- Copy and paste the content of your SSH public key (e.g.,
id_rsa_company2.pub) into the "Key" field.
- Click Add key.
- For a User:
- Log in to your Azure DevOps account.
- Click on your profile picture at the top right, then select Security.
- Under “SSH public keys”, click on + New Key.
- Provide a description and then copy and paste the content of your SSH public key (e.g.,
id_rsa_company1.pub) into the provided field.
- Click Save.
Create an SSH Config File
Create or edit the SSH config file in
and use the private ssh key generate on step 1 :
# company 1 on Azure DevOps
# company 2 on gitlab
Use the SSH Config in Git
When cloning a repository, use the alias you set in your SSH config file.
For the first organization azure :
git clone git@azure-company:company1/repo.git
For the second organization gitlab:
git clone git@gitlab:company2/repo.git
For existing repositories, you can check and change the remote URL:
git remote -v
#if result of youre url is an HTTP you can use the command bellow to set the Git url
git remote set-url origin git@azure-company:company1/repo.git
By following these steps, you can maintain multiple SSH keys for different organizations or repositories on platforms like GitHub, GitLab, Bitbucket, and others.
i hope this will help ,If you have any further questions or run into issues, don’t hesitate to reach out.