So you want to have different ssh keys for your GitHub and GitLab account because… why not?
Or you just want to know how to make your life easier by doing ssh machine, instead of ssh user@some_ip?
Direct answer(for the first question second is in BTW section): #
- Go to ~/.ssh
cd ~/.ssh/
- Create different ssh keys for your different usecases
ssh-keygen -t ed25519 -f github_key -C "github ssh key"
with:
github_key
: beign the name of the generated key-C
: stands for comment.
- Create a file name config
touch config
- use your text editor of choice to open it for me its neovim
nvim config
put this inside the config
file
# file you are editing the file `~/.ssh/config`
## Gitlab account
## gitla is the name of the gitlab key
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitla
## Github account
## github is the name of the key you want to use with github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github
- Save the file and quit :wq
- test if everything is working
# with github
ssh -T git@github.com
# with gitlab
ssh -T git@gitlab.com
BTW #
You can also add your ssh machines, and make your life easier
# Debian machine!
Host deb1
HostName 123.456.789.10
User root
now you only need to do
ssh deb1
And if you want to learn more about this whole ssh thingy, you can go to the official Bsd doc and i wish you GOOD LUCK
Long boring story struggle story version #
- First you spend 2h searching why when you create a key with a different name
then the github key doesn’t work and you can’t push pull or clone in GitHub, because you are not that good at duck ducking stuff( or maybe it is duck duck go !!)
-
Then you ask some clever people, telling you that the problem isn’t GitHub as you expected (you realize that you have been doing the wrong researches!!)
-
after that you got this link but it really looks scary! so what you do? You search in that direction! And BIM bam boom you find the “perfect one” BUT you don’t want to take “risks” in your own computer, so you fire up a vm! hmm, you recreate the problem blablabla but the vm is Ubuntu server and the terminal isn’t that beautiful so you say hay let’s install oh-my-zsh, and then ….well you need to copy and paste from your machine to the VM(I’m lazy i don’t want to rewrite stuff OK ) , but ow even when the share clipboard bidirectional is on … it doesn’t work! soo what you do?
-
Let’s ssh into it! But … wait a second! I don’t know how to ( I forget 😢 ) so you search how to get the IP address check if the OpenSSH server and client is installed etc https://phoenixnap.com/kb/ssh-to-connect-to-remote-server-linux-or-windows , and then you write
ssh username@ip_adress
and then you wait… you wait.. you wait… and nothing’s happening, so you try again, lookup for another tutorial! Well same thing, another hour is gone. So you think? What’s the risk anyway, let’s do it!!
You follow the tutorial! you create the config file inside the ~/.ssh directory and copy what the tutorial say, and it works with GitHub but not with GitLab. Lucky for you, you figure out what’s the problem by going into the GitLab documentation . And then finally! Everything work and you can clone that GitHub repo of that CSS tutorial you were watching At the end of the day you could’ve just used https you know.