Make your Linux OS ready for GitHub, GitLab & BitBucket altogether

Make your Linux OS ready for GitHub, GitLab & BitBucket altogether

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

  1. 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.

  2. Then go to the key section of the GitHub settings.

  3. 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"
    
  4. 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 :
    /home/user_name/.ssh/id_github
    
    Like, my user name is fba_desktop. That is why I applied /home/fba_desktop/.ssh/id_github as the address.
  5. 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 with id_github as well. I would recommend you to skip this if you don't necessarily need this by pressing the Enter key. I have not used this as well as I have not found the necessity of it within my Desktop computer.
  6. Start the ssh-agent in the background.
    eval "$(ssh-agent -s)"
    
    Depending on your environment, you may need to use a different command. For example, you may need to use root access by running sudo -s -H before starting the ssh-agent, or you may need to use exec ssh-agent bash or exec ssh-agent zsh to run the ssh-agent.
  7. 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 using id_ed25519.
    ssh-add ~/.ssh/id_github
    
  8. For adding the new SSH key to your GitHub account, go to the SSH Keys page of your GitHub settings.
  9. Copy the SSH public key to your clipboard. Open the terminal and use the following command.
    cat ~/.ssh/id_github.pub
    # Then select and copy the contents of the id_github.pub file
    # displayed in the terminal to your clipboard
    
    Tips: Alternatively, you can 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 id_github file in your favorite text editor, and copy it to your clipboard.
  10. Click on the Green button indicating New SSH Key.
  11. Give a suitable title you want.
  12. Paste the key in the key box.
  13. Add the SSH key.
  14. Now you may close the browser tab as well.
  15. 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"
    
  16. 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
    
  17. Your PC is completely ready for GitHub from now on.
  18. For your convenience, I have described everything in a YouTube video as well. You might check that out also from here.

GitLab

  1. 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.
  2. Then go to the SSH key section of the GitHub settings.
  3. 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>"
    
  4. 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 :
    /home/user_name/.ssh/id_gitlab
    
    Like, my user name is fba_desktop. That is why I applied /home/fba_desktop/.ssh/id_gitlab as the address.
  5. At the prompt, type a secure passphrase if you want. For more information, see "Passphrases.". You need to substitute id_ed25519 with id_gitlab as well. I would recommend you to skip this if you don't necessarily need this by pressing the Enter key. I have not used this as well as I have not found the necessity of it within my Desktop computer.
  6. Start the ssh-agent in the background.
    eval $(ssh-agent -s)
    
  7. 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 using id_ed25519.
    ssh-add ~/.ssh/id_gitlab
    
  8. For adding the new SSH key to your GitLab account, go to the SSH Keys page of your GitHub settings.
  9. Open the terminal and use the following command.
    xclip -sel clip < ~/.ssh/id_gitlab.pub
    
    If it shows that Command `xclip` not found, then enter the following command first within the terminal:
    sudo apt install xclip
    
    After then, run the previous command once again. Tips: Alternatively, you can 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 id_gitlab file in your favorite text editor, and copy it to your clipboard.
  10. Go to the SSH Keys page of your GitLab settings.
  11. Give a suitable title you want.
  12. Paste the key in the key box.
  13. Add the SSH key.
  14. Now you may close the browser tab as well.
  15. 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"
    
  16. 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
    
  17. Your PC is completely ready for GitLab from now on.
  18. For your convenience, I have described everything in a YouTube video as well. You might check that out also from here.

BitBucket

  1. 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.
  2. Then go to the SSH key section of the BitBucket settings.
  3. 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
    
  4. 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 :
    /home/user_name/.ssh/id_bitbucket
    
    Like, my user name is fba_desktop. That is why I applied /home/fba_desktop/.ssh/id_bitbucket as the address.
  5. 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 with id_bitbucket as well. I would recommend you to skip this if you don't necessarily need this by pressing the Enter key. I have not used this as well as I have not found the necessity of it within my Desktop computer.
  6. Start the ssh-agent in the background.
    eval $(ssh-agent)
    
  7. 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 use id_bitbucket here instead of using id_rsa.
    ssh-add ~/.ssh/id_bitbucket
    
  8. For adding the new SSH key to your BitBucket account, go to the SSH Keys page of your BitBucket settings.
  9. 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 file id_bitbucket.pub in your favorite text editor, and copy it to your clipboard.
  10. Go to the SSH Keys page of your BitBucket settings.
  11. Give a suitable label you want.
  12. Paste the key in the key box.
  13. Add the SSH key.
  14. Now you may close the browser tab as well.
  15. 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"
    
  16. 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
    
  17. Your PC is completely ready for BitBucket from now on.
  18. 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.