SSH Configs
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.
A ssh .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
-
alias
is an alias that you may specify i.e. in order tossh
into remote servers. -
hostname
is the name of the server i.e.gitlab.ethz.ch
-
User
is your gitlab username i.e. forgitlab.ethz.ch
it is you nethz username. -
IdentityFile
is the path to you local private ssh key i.e..ssh/id_rsa
Creating A config file
- Change into your home directory:
cd
- Change into your ssh directory:
cd .ssh
- Create a ssh config file:
touch config
- 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.id_rsa_gitlab_ethz
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 HostName
).
Host gitlab.ethz.ch
HostName gitlab.ethz.ch
User username
IdentityFile ~/.ssh/id_rsa_ethz
Cloning the repo is then:
$ git clone git@gitlab.ethz.ch:pt1_hs20/lecture.git