GitLab generate and add SSH keys

15/08/2023 • 2 min read

Are you keep coming back to remember what commands to use when you need to setup your GitLab? Whether you're using Windows, macOS, or Linux, I've got you covered.

Seashell shaped lock getting unlocked

Windows

Open Git Bash and follow.

  1. Generate SSH Keys: If you don't already have SSH keys, you can generate them using Git Bash.

    cd ~/.ssh
    ssh-keygen -t rsa -b 4096 -C "example@berkekaragoz.com"
    
  2. Start SSH Agent: Run the following command in Git Bash to start the SSH agent:

    eval "$(ssh-agent -s)"
    
  3. Add SSH Key to Agent: Add your SSH private key to the SSH agent:

    ssh-add ~/.ssh/name_of_the_key
    
  4. Copy Public Key: Copy your SSH public key to the clipboard:

    clip < ~/.ssh/name_of_the_key.pub
    
  5. Add Public Key to GitLab: Log in to your GitLab account. Go to "Settings" > "SSH Keys." Add the copied key and save it.

  6. Test Connection: In Git Bash, run:

    ssh -T git@gitlab.com
    

macOS

  1. Generate SSH Keys: If you don't have SSH keys, generate them by running:

    ssh-keygen -t rsa -b 4096 -C "example@berkekaragoz.com"
    
  2. Start SSH Agent: Start the SSH agent:

    eval "$(ssh-agent -s)"
    
  3. Add SSH Key to Agent: Add your SSH private key to the SSH agent:

    ssh-add -K ~/.ssh/name_of_the_key
    
  4. Copy Public Key: Copy your SSH public key to the clipboard:

    pbcopy < ~/.ssh/name_of_the_key.pub
    
  5. Add Public Key to GitLab: Log in to your GitLab account. Go to "Settings" > "SSH Keys." Add the copied key and save it.

  6. Test Connection: In the terminal, run:

    ssh -T git@gitlab.com
    

Linux

  1. Generate SSH Keys: If you don't have SSH keys, generate them using:

    ssh-keygen -t rsa -b 4096 -C "example@berkekaragoz.com"
    
  2. Start SSH Agent: Start the SSH agent:

    eval "$(ssh-agent -s)"
    
  3. Add SSH Key to Agent: Add your SSH private key to the SSH agent:

    ssh-add ~/.ssh/name_of_the_key
    
  4. Copy Public Key: Copy your SSH public key to the clipboard:

    cat ~/.ssh/name_of_the_key.pub | xclip -selection clipboard
    
  5. Add Public Key to GitLab: Log in to your GitLab account. Go to "Settings" > "SSH Keys." Add the copied key and save it.

  6. Test Connection: In the terminal, run:

    ssh -T git@gitlab.com
    

Now, you can interact with your repositories without the hassle of entering credentials every time.

You can add them to GitHub as well, so you get the cool verified badge on your commits :>

"GitLab generate and add SSH keys", 15/08/2023, 01:30:00

#git, #guide, #linux, #ssh