Create a ssh key for your GitLab project on IBM Cloud

This blog post is a short cheat sheet to remember how to configure the access to a GitLab project on IBM Cloud from a local computer. An important part in that situation is you need to configure a ssh key for your computer and save this key in GitLab on IBM Cloud. The remaining parts is how to use GitLab pretty straight forward and good described in the official GitLab documentation. That blog post is related to this blog entry “Example usage of the internal IBM Cloud GitLab instance“.

These are the steps I want to note.

Step 1: Open a terminal and open the .ssh folder on your computer

cd ~/.ssh
ls

Step 2: Create a new SSH key

ssh-keygen -t rsa -C "my_ibm_gitlab_rsa" -f "my_ibm_gitlab_rsa"

  • Example output:
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in my_ibm_gitlab_rsa
Your public key has been saved in my_ibm_gitlab_rsa.pub
The key fingerprint is:
SHA256:JMxwCMmnRwWqxNkM1jZ+cImY my_ibm_gitlab_rsa
The key's randomart image is:
+---[RSA 3072]----+
|O%=+o            |
|X.Oo=*           |
|.B.=o * .        |
|oEo..= o         |
|=o.*.   S        |
| B               |
| o +             |
|    o            |
|                 |
+----[SHA256]-----+

Step 3: Verify that the files exists

 ls
  • Example output:
id_rsa                                  known_hosts.old
id_rsa.pub                              
my_ibm_gitlab_rsa            
my_ibm_gitlab_rsa.pub

Step 4: Create a new ssh key on the https://eu-de.git.cloud.ibm.com/-/profile/keys

Step 5: Open the file with an editor and copy the content of the public key into the new key on https://eu-de.git.cloud.ibm.com/-/profile/keys for your GitLab project (as you can see above).

nano my_ibm_gitlab_rsa.pub

Step 6: Add the ssh key to a local config file (see in the documentation generate a ssh key pair

eval $(ssh-agent -s)
ssh-add ~/.ssh/my_ibm_gitlab_rsa

Step 7: Create a new config file

nano ~/.ssh/config

Step 8: Adjust the content for the configfile

# Private GitLab instance
Host eu-de.git.cloud.ibm.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/my_ibm_gitlab_rsa

Step 9: Ensure you have set the right Git global settings

git config --global user.name "thomas.suedbroecker"
git config --global user.email "thomas.suedbroecker@de.ibm.com"

I hope this was useful for you and let’s see what’s next?

Greetings,

Thomas

#ibmcloud , #gitlab, #toolchain

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: