connect_with_gitlab_using_ssh - XLRIT/gears GitHub Wiki
Connecting your gitlab (or any other git) using SSH is preferred because no secrets are send over the internet. Also, you do not have to enter your password anymore and only your laptop can connect to gitlab. Instead you simply have to set it up and replace your ssh keys once every say year or so. This is the quick guide to set this up on a Windows machine.
NOTE!! user
edwin
is an example username, replace that with your own username.
Required steps
- On your Windows machine open Command prompt
- commands
C:
cd \Users\edwin\.ssh
ssh-keygen -t ed25519 -C "edwin's XLRIT laptop"
- Press enter a couple of times to accept the defaults of the
ssh-keygen
command.
Now 2 files have been generated:
id_ed25519
: your private key (which is secret and should never leave your laptop)id_ed25519.pub
: your public key
- Open https://gitlab.xlrit.com/-/profile menu SSH Keys copy paste the content of your public key into the field Key and click button Add key
It should already work now (you can verify this with command ssh -T [email protected]
; it should say Welcome to GitLab, @edwin!
). You should be able can do all sorts of git. For instance clone projects. Of course now you should Clone with SSH instead of HTTPS.
Note: that the key will expire (by default in a year). This is easy to forget, so perhaps you want to set a reminder in your calendar.
Optional steps to use different keys for different systems
You can have different systems you want to communicate with it may be useful to have specific keys for each (group of) systems. This is how to do it:
- Rename the private and public key to whatever you like. In this example to
edwin_at_gitlab.xlrit.com
adnedwin_at_gitlab.xlrit.com.pub
. - In file
C:\Users\edwin\.ssh\config
add the following:
Host gitlab.xlrit.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/edwin_at_gitlab.xlrit.com
- Save the file.
It should now work with the renamed file as well.