0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

How to add multiple ssh keys for the same host

Last updated at Posted at 2023-05-24

Create ssh directory

mkdir ~/.ssh
mkdir ~/.ssh/github
mkdir ~/.ssh/devops

Create ssh key

ssh key for Github

ssh-keygen -t rsa -b 4096 -f ~/.ssh/github/${accountName}/id_rsa -C "test@mail.com"

ssh key for Azure DevOps

ssh-keygen -t rsa -b 4096 -f ~/.ssh/devops/${organizationName}/id_rsa -C "test@mail.com"

Create .ssh/config

vi ~/.ssh/config
Host github-${accountName}
HostName github.com
  User git
  AddKeysToAgent yes
  IdentitiesOnly yes
  UseKeychain yes
  IdentityFile ~/.ssh/github/${accountName}/id_rsa

Host devops-${organizationName}
HostName ssh.dev.azure.com
  User git
  AddKeysToAgent yes
  IdentitiesOnly yes
  UseKeychain yes
  IdentityFile ~/.ssh/devops/${organizationName}/id_rsa

Copy and paste public key to Github

pbcopy < ~/.ssh/github/${accountName}/id_rsa.pub

Copy and paste public key to AzureDevOps

pbcopy < ~/.ssh/devops/${organizationName}/id_rsa.pub

Clone repository

Github

git clone git@github-${accountName}:${accountName}/${projectName}.git

DevOps

git clone git@devops-${organizationName}:v3/${organizationName}/${projectName}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?