By AriesZhou · · 1 min read
Configuring SSH Access for Multiple Git Repositories
Git
- Navigate to the SSH configuration path, usually
~/.ssh - 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-keygento create an RSA key pair by default. You can also customize it with parameters, such as./ssh-keygen -t ed25519 -C usernameetc. - eval
ssh-agent -s - ssh-add repo1-deploy-key repo2-deploy-key
- Copy the contents of filename.pub
- Paste it into the Git repository under Settings—Deploy Keys—Add deploy key
- Modify
~/.ssh/configas 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
- Update the
.git/configURL 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.