Back to Blog
By AriesZhou · · 1 min read

Configuring SSH Access for Multiple Git Repositories

Git

  1. Navigate to the SSH configuration path, usually ~/.ssh
  2. Create an SSH key pair and follow the prompts to name the files (e.g., repo1-deploy-key, repo2-deploy-key). For a simple command, use ./ssh-keygen to create an RSA key pair by default. You can also customize it with parameters, such as ./ssh-keygen -t ed25519 -C username etc.
  3. eval ssh-agent -s
  4. ssh-add repo1-deploy-key repo2-deploy-key
  5. Copy the contents of filename.pub
  6. Paste it into the Git repository under Settings—Deploy Keys—Add deploy key
  7. Modify ~/.ssh/config as follows
Host repo1.github.com
        HostName github.com
        AddKeysToAgent yes
        IdentityFile ~/.ssh/repo1-deploy-key

Host repo2.github.com
        HostName github.com
        AddKeysToAgent yes
        IdentityFile ~/.ssh/blog-repo
  1. Update the .git/config URL in the repo1 and repo2 directories respectively, as follows
//url = git@github.com:username/repo1.git
url = git@repo1.github.com:username/repo1.git

Failed to connect to github.com port 443: Timed out.

Change the https URL in the .git/config file to the Git repository’s SSH URL.