When you start to work with multiple remote servers you may run into problems.
This is because your computer does no longer know which ssh-key to provide for which server.
But don't you worry! ssh config to the rescue.
.ssh/config file can help you to manage multiple ssh-keys and is simply a text file (without .txt extension)
where each remote is specified like this:
Host aliases HostName hostname User username IdentityFile .ssh/keyname
aliasis an alias that you may specify i.e. in order to
sshinto remote servers.
hostnameis the name of the server i.e.
Useris your gitlab username i.e. for
gitlab.ethz.chit is you nethz username.
IdentityFileis the path to you local private ssh key i.e.
Creating A config file
- Change into your home directory:
- Change into your ssh directory:
- Create a ssh config file:
- Edit the ssh config file as fit
Sidenote: when using multiple ssh keys its best to give them descriptive names when creating them i.e.
Using Git after setting up a config file
If you provide an alias to a Host in your git config file you need to access this host with the same alias.
Host gitlab_account_1 HostName gitlab.ethz.ch User username IdentityFile ~/.ssh/id_rsa_ethz
cloning the repo is then:
$ git clone git@gitlab_account_1:pt1_hs20/lecture.git
If you only have one account to a server it is recommended to not give an alias (use the same for
Host as for
Host gitlab.ethz.ch HostName gitlab.ethz.ch User username IdentityFile ~/.ssh/id_rsa_ethz
Cloning the repo is then:
$ git clone firstname.lastname@example.org:pt1_hs20/lecture.git