Backstory
After setting up my computer, the first thing I always do is set up that machine for my GitHub, GitLab and BitBucket accounts altogether using unique SSH keys for all of them. However, the mentioned task is very simple for me in the Windows Operating Systems. I find myself in hardship doing those in a Linux-based distro. I searched a lot for getting any good hints to make myself able to do that like I am doing in any Windows-based OS, but I couldn't find that at all. After experimenting a lot, yesterday I have found that exact way I was looking for until yesterday. I am going to explain each detail and procedure here as well. I am using Pop!_OS here which is actually a Debian based distro, but you can apply this exact procedure in other Linux distro (RPM/Arch/etc.) as well by simply changing the command accordingly like, sudo dnf
instead of using sudo apt
in fedora and so on.
How this article might help you?
After setting up a Linux machine, many of us simply generate an SSH key and add that to our git provider ( GitHub / GitLab / BitBucket ). We do that simply by going to the site and following their instructions. As they all show to use the ed25519
algorithm, it's hard to distinguish all three of them differently if we want to use the same ed25519
for GitHub, GitLab and BitBucket altogether. However, I am using a very simple trick to use three different SSH keys using the same ed25519
algorithm here. If you have already faced any issue regarding using different SSH keys using the same ed25519
algorithm in multiple platforms (such as GitHub, GitLab & BitBucket altogether), then this article might help you greatly!
Get Started!
Pre-requisite
- We need to perform updates and upgrade in our OS first. Open the terminal and follow the next procedures as well.
sudo apt update && sudo apt upgrade -y
- You may also want to check the git version as well to see if that is working well or not.
git --version
Currently, I am getting git version 2.30.2
(as of 22 October 2021). If you are reading this article later while the git version upgrades then you would find a change in the git version. Don't worry! The procedures will work flawlessly.
- Now we are ready to dive into the GitHub, GitLab and BitBucket sections. I will show the procedures of GitHub first, then GitLab and in the last, BitBucket; but you don't need to follow the three platforms serially. You can alter the sequence as you like but follow the procedures exactly within a single provider. I mean, if you are following the GitLab section, then do everything accordingly I have shown you in the GitLab section, but you can go for BitBucket first, then GitLab, or anything like that.
GitHub
Head over to the GitHub and sign in to your account if you have already an existing account. If you don't have an account created already, then you can also sign up for an account freely.
Then go to the key section of the GitHub settings.
Now, I will generate a new SSH key and add it to the ssh-agent as well. Open the terminal and paste the text below, substituting in your GitHub email address.
ssh-keygen -t ed25519 -C "your_email@example.com"
- When you're prompted to "Enter a file in which to save the key," then paste the following to the terminal, substituting your user name in the address :
Like, my user name is fba_desktop. That is why I applied/home/user_name/.ssh/id_github
/home/fba_desktop/.ssh/id_github
as the address. - At the prompt, type a secure passphrase if you want. For more information, see "Working with SSH key passphrases.". You need to substitute
id_ed25519
withid_github
as well. I would recommend you to skip this if you don't necessarily need this by pressing theEnter
key. I have not used this as well as I have not found the necessity of it within my Desktop computer. - Start the ssh-agent in the background.
Depending on your environment, you may need to use a different command. For example, you may need to use root access by runningeval "$(ssh-agent -s)"
sudo -s -H
before starting the ssh-agent, or you may need to useexec ssh-agent bash
orexec ssh-agent zsh
to run the ssh-agent. - Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file. As for this, we will use
id_github
here instead of usingid_ed25519
.ssh-add ~/.ssh/id_github
- For adding the new SSH key to your GitHub account, go to the SSH Keys page of your GitHub settings.
- Copy the SSH public key to your clipboard. Open the terminal and use the following command.
Tips: Alternatively, you can locate the hidden .ssh folder (You have to enable thecat ~/.ssh/id_github.pub # Then select and copy the contents of the id_github.pub file # displayed in the terminal to your clipboard
Show hidden files/folder
from your file manager settings in order to get the hidden folders/files), open theid_github
file in your favorite text editor, and copy it to your clipboard. - Click on the Green button indicating
New SSH Key
. - Give a suitable title you want.
- Paste the key in the key box.
- Add the SSH key.
- Now you may close the browser tab as well.
- Open a terminal and follow the commands as well.
git config --global user.name "Your_User_Name" git config --global user.email "Your_User_Email_That_You_Use_In_Your_GitHub_Account"
- We will now clone a PRIVATE REPOSITORY from your GitHub account to your local machine. If you don't have any private repository in your GitHub account yet now, then you may simply create a new repository as well and follow the steps provided in your GitHub repo.
git clone # The SSH key of that repo
- Your PC is completely ready for GitHub from now on.
- For your convenience, I have described everything in a YouTube video as well. You might check that out also from here.
GitLab
- Head over to the GitLab and sign in to your account if you have already an existing account. If you don't have an account created already, then you can also sign up for an account freely.
- Then go to the SSH key section of the GitHub settings.
- Now, I will generate a new SSH key and add it to the ssh-agent as well. Open the terminal and paste the text below, substituting in your GitLab email address.
ssh-keygen -t ed25519 -C "<Your_Email_Address>"
- When you're prompted to "Enter a file in which to save the key," then paste the following to the terminal, substituting your user name in the address :
Like, my user name is fba_desktop. That is why I applied/home/user_name/.ssh/id_gitlab
/home/fba_desktop/.ssh/id_gitlab
as the address. - At the prompt, type a secure passphrase if you want. For more information, see "Passphrases.". You need to substitute
id_ed25519
withid_gitlab
as well. I would recommend you to skip this if you don't necessarily need this by pressing theEnter
key. I have not used this as well as I have not found the necessity of it within my Desktop computer. - Start the ssh-agent in the background.
eval $(ssh-agent -s)
- Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file. As for this, we will use
id_gitlab
here instead of usingid_ed25519
.ssh-add ~/.ssh/id_gitlab
- For adding the new SSH key to your GitLab account, go to the SSH Keys page of your GitHub settings.
- Open the terminal and use the following command.
If it shows thatxclip -sel clip < ~/.ssh/id_gitlab.pub
Command `xclip` not found
, then enter the following command first within the terminal:
After then, run the previous command once again. Tips: Alternatively, you can locate the hidden .ssh folder (You have to enable thesudo apt install xclip
Show hidden files/folder
from your file manager settings in order to get the hidden folders/files), open theid_gitlab
file in your favorite text editor, and copy it to your clipboard. - Go to the SSH Keys page of your GitLab settings.
- Give a suitable title you want.
- Paste the key in the key box.
- Add the SSH key.
- Now you may close the browser tab as well.
- Open a terminal and follow the commands as well.
git config --global user.name "Your_User_Name" git config --global user.email "Your_User_Email_That_You_Use_In_Your_GitHub_Account"
- We will now clone a PRIVATE REPOSITORY from your GitLab account to your local machine. If you don't have any private repository in your GitLab account yet now, then you may simply create a new repository as well and follow the steps provided in your GitLab repo.
git clone # The SSH key of that repo
- Your PC is completely ready for GitLab from now on.
- For your convenience, I have described everything in a YouTube video as well. You might check that out also from here.
BitBucket
- Head over to the [BitBucket(bitbucket.org) and sign in to your account if you have already an existing account. If you don't have an account created already, then you can also sign up for an account freely.
- Then go to the SSH key section of the BitBucket settings.
- Now, I will generate a new SSH key and add it to the ssh-agent as well. Open the terminal and paste the text below, substituting in your BitBucket email address.
ssh-keygen
- When you're prompted to "Enter a file in which to save the key," then paste the following to the terminal, substituting your user name in the address :
Like, my user name is fba_desktop. That is why I applied/home/user_name/.ssh/id_bitbucket
/home/fba_desktop/.ssh/id_bitbucket
as the address. - At the prompt, type a secure passphrase if you want. For more information, see "Set up an SSH key.". You need to substitute
id_rsa
withid_bitbucket
as well. I would recommend you to skip this if you don't necessarily need this by pressing theEnter
key. I have not used this as well as I have not found the necessity of it within my Desktop computer. - Start the ssh-agent in the background.
eval $(ssh-agent)
- Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace
id_rsa
in the command with the name of your private key file. As for this, we will useid_bitbucket
here instead of usingid_rsa
.ssh-add ~/.ssh/id_bitbucket
- For adding the new SSH key to your BitBucket account, go to the SSH Keys page of your BitBucket settings.
- Locate the hidden .ssh folder (You have to enable the
Show hidden files/folder
from your file manager settings in order to get the hidden folders/files), open the fileid_bitbucket.pub
in your favorite text editor, and copy it to your clipboard. - Go to the SSH Keys page of your BitBucket settings.
- Give a suitable label you want.
- Paste the key in the key box.
- Add the SSH key.
- Now you may close the browser tab as well.
- Open a terminal and follow the commands as well.
git config --global user.name "Your_User_Name" git config --global user.email "Your_User_Email_That_You_Use_In_Your_GitHub_Account"
- We will now clone a PRIVATE REPOSITORY from your GitLab account to your local machine. If you don't have any private repository in your BitBucket account yet now, then you may simply create a new repository as well and follow the steps provided in your BitBucket repo.
git clone # The SSH key of that repo
- Your PC is completely ready for BitBucket from now on.
- For your convenience, I have described everything in a YouTube video as well. You might check that out also from here.
Now your PC is completely ready for working on GitHub, GitLab & BitBucket simultaneously. You may follow me on GitHub, GitLab, Twitter, YouTube, LinkedIn as well.