DEV Community

Cover image for Setup Multiple SSH Key's
Edisson Ballesteros Aguilar
Edisson Ballesteros Aguilar

Posted on • Edited on

Setup Multiple SSH Key's

Sometimes you will need to deal with multiple projects at the same time, some client with AWS, Gitlab, Github etc.
Here are some steps that could be helpful ;)

1. Create a new SSH Key

ED25519

ssh-keygen -t ed25519 -C "<comment>"
Enter fullscreen mode Exit fullscreen mode

RSA 2048

ssh-keygen -t rsa -b 2048 -C "<comment>"
Enter fullscreen mode Exit fullscreen mode

2. Add SSH Key

eval $(ssh-agent -s)
ssh-add <directory to private SSH key>
Enter fullscreen mode Exit fullscreen mode

3. Setup config

Touch or update the config file in ~/.ssh/:

Host gitlab-scope
  HostName gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab_com_rsa
Enter fullscreen mode Exit fullscreen mode

AWS Codecommit

Host aws-codecommit
  HostName git-codecommit.{region}.amazonaws.com
  User APKARF3PHVLQ1EXAMPLE
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/private_key
  PubkeyAcceptedAlgorithms +ssh-rsa
  HostkeyAlgorithms +ssh-rsa
Enter fullscreen mode Exit fullscreen mode

Hostnames

  • Gitlab: gitlab.com
  • Github: github.com
  • AWS Codecommit: git-codecommit.{region}.amazonaws.com

4. Setup public key

cat private_key.pub
Enter fullscreen mode Exit fullscreen mode
ssh-ed25519 ABBBC3NzaC1lZDI1NTE5AAAAIBSFa3klpakF4ZkNPO7JWMsQDqy3Wd6ZvyPslt <comment>
Enter fullscreen mode Exit fullscreen mode

Copy the key to your repository preferences and create the SSH key

5. Verify the connection

ssh -T git@gitlab-scope
Enter fullscreen mode Exit fullscreen mode
The authenticity of host 'gitlab.com (172.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:hfksfbdfoerHKSDKFDFDFDF.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,172.0.0.1' (ECDSA) to the list of known hosts.
Welcome to GitLab, @user!
Enter fullscreen mode Exit fullscreen mode

6. Clone the repository

git clone git@gitlab-scope:project/repository-name.git
Enter fullscreen mode Exit fullscreen mode

AWS Codecommit

git clone ssh://aws-codecommit/v1/repos/repository-name
Enter fullscreen mode Exit fullscreen mode

Top comments (0)