Use SSH to pull two Git projects on a Linux server, and the corresponding two projects areDifferent Git accounts (SSH Key),practice:
Use SSH Config to configure multiple Git accounts
Scenario Assumptions:
- The warehouse address of Project A:
git@:company-a/
- Project B's warehouse address:
git@:company-b/
- The SSH key used by Project A is:
~/.ssh/id_rsa_company_a
- The SSH key used by Project B is:
~/.ssh/id_rsa_company_b
1. Generate two SSH keys (if not)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_company_a ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_company_b
Then put these two*.pub
The public key is added to the SSH settings of the respective Git platform accounts.
2. Edit the SSH configuration file
vim ~/.ssh/config
Add the following configuration (ornano
edit):
# Configure Git access for Company AHost github-company-a HostName User git IdentityFile ~/.ssh/id_rsa_company_a # Configure Git access for Company BHost github-company-b HostName User git IdentityFile ~/.ssh/id_rsa_company_b
3. Modify the Git repository address and use SSH to configure Host
⚠️ Note: The default one cannot be used
git@
, and change it to the alias you definedgithub-company-a
orgithub-company-b
。
For example:
Clone Project A:
git clone git@github-company-a:company-a/
Clone Project B:
git clone git@github-company-b:company-b/
✅ Verification
You can verify that the different keys are loaded correctly by the following command:
ssh -T git@github-company-a ssh -T git@github-company-b
📌 Tip
Ensure that the two private key files have permissions of 600:
chmod 600 ~/.ssh/id_rsa_company_*
If deployed on a CI/CD environment or server, you canssh/config
and private keys are deployed through environment variables or automated methods.
This is the end of this article about using SSH to pull multiple Git projects on Linux servers. For more related linux servers to pull multiple Git content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!