Gitlab repositories and ssh keys Pt 2

Hmm, I was supposed to put in the process and commands in pt. 2 but somehow I seem to have forgotten that.
Anyway lets start.
1. Create SSH Key for development PC.

I did not have any old keys n ~/.ssh so went ahead with below command to create a new one.
$ ssh-keygen -t rsa -C "your_email@example.com"
Rest all is straight-forward. At the end you have a private key and a public key.

2. Add this key to gitlab.
Open your gitlab server instance ( e.g. gitlab.xyz.com etc ). Then login with your credentials. After logging in, go to user settings by clicking on the user menu at top left corner and clicking on Edit profile option. This will open User Settings page. Here at left side is a list. Click SSH Keys in this list. This will open the SSH Keys setting page. Here you can paste the public key in the .pub file which you generated above. DO NOT PASTE PRIVATE KEY, as it is PRIVATE!!!

3. Add your ssh key to the repository.
Now go to your repository / your fork of an upstream repository. In main page, on left side is a list. Click on Settings > Repository. This will open Repository Settings page. On this page expand Deploy Keys option. Here below is a listing of Enabled keys, Privately Accessible keys and Publically Accessible keys. Let me explain in a bit whats each. Privately Accessible keys are your personal keys which you have not marked as shared. This means your develpment PC in this case is not shared and only you have access to it. Next Publically Accessible keys are keys for shared build machines. These machines are accessible to multiple people and usually deploy a build runner ( CI/CD part ). Anyway our key should be visible in Privately Accessible keys portion. There's an Enable button to enable it.
Also if you are going to use the development desktop to write to your fork - like pushing your changes to the server, then you will need write access enabled for this key.
To do this, since now the key is visible in Enabled deploy keys tab, click on the pencil icon for edit button, and in next screen check "Grant write persissions to this key".

4. Git clone and git push using the new ssh key.
Now on development desktop try to clone your repository / fork using git clone, and use git:// URL.
This should automatically clone the repo. And once your patch is ready and committed, git push origin [branch-name] should also sync without asking you any credentials.
So the credentials check is now happening by using your ssh key for the development PC.

Note: In Ubuntu and many other distro's they have a secure key-store. In case you use that to secure your private key, then you will most probably end up using a password. And a pop-up will come up after first git clone / git push command to ask you to enter password to unlock the keyring. For me, this is needed only once per session. Just some extra security to ensure others don't misuse the SSH key access.

Comments

Popular posts from this blog

Morning Quotes

QCalendarWidget CSS Stylesheeting

Selecting new phone plan