type
status
date
slug
summary
tags
category
icon
password
If we want to access different GitHub accounts through SSH, we can achieve that with the following configuration.
Assuming you have two GitHub accounts, one is a personal GitHub account
personal, and the other is a work company account work.To be able to access different GitHub accounts under the same user on the same PC, you need to configure it as follows.
Account | personal | work |
Email | ||
Host | github.com-personal | github.com-work |
IdentityFile | ~/.ssh/personal_rsa | ~/.ssh/work_rsa |
🔐 Generate SSH Keys
You can refer to the content of the following article to generate a new SSH key.
Here we want to emphasize that when creating different keys, not only should they be differentiated by labels, but it is also recommended to differentiate the generated key files. You can use the following commands to create different key files:
➕ Add Keys
Add SSH keys to the GitHub account: Log in to the GitHub website and access the settings page of each account. Then, follow these steps to add SSH keys:
- Click on the avatar icon in the top right corner of the page and select "
Settings".
- In the left sidebar, click on "
SSH and GPG keys".
- Click the "
New SSH Key" button.
- In the "
Title" field, provide a descriptive name for the key (e.g., "Personal Account SSH Key").
- Open the SSH key file you generated (usually located in the
~/.ssh/directory) and copy the public key content.
- Paste the public key into the "
Key" field.
- Click the "
Add SSH key" button to save and add the key.
☑️ Configure SSH Host Aliases
To differentiate between different GitHub accounts, you can set aliases for each account in the SSH configuration file. Open the SSH configuration file (usually located at
~/.ssh/config) and add the following content:🔗 SSH Access
Now, we can use SSH to access different GitHub accounts. For example, to clone a repository from the personal account, you can use the following command:
Replace
username/repo.git with the full path of the repository you want to clone from the personal account. Similarly, you can access repositories of other accounts using the respective aliases.This way, you can use different SSH keys to access repositories of different GitHub accounts on the same PC. Make sure to use the correct key and account when performing sensitive operations.
- 作者:KaiGuo
- 链接:https://blog.kaiguov5.com/article/a7bc090e-d901-4a0a-a21f-c63f9b6e63cb
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
