进到 .ssh 目录 code ~/.ssh
实现: github.com 的项目使用github 的账号
就一个 github 账号
config文件内容
# 公司 gitlab; 对 http 无效
Host github.com
HostName github.com
User git
# 走 socks5 代理
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
IdentityFile ~/.ssh/id_ed25519
# Fig ssh integration. Keep at the bottom of this file.
Match all
Include ~/.fig/ssh
最下面的 fig 可忽略
多个 github 账号
HostName 重新起个名字, 仓库与名字绑定
1- Generate a new SSH key for each of your accounts:
`ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/github_account1`
`ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/gitlab_account1`
2- Add the public keys (*.pub files) to your GitHub and GitLab accounts.
3- Create a new SSH configuration file for each account:
Bash
`touch ~/.ssh/config.github_account1`
`touch ~/.ssh/config.gitlab_account1`
4- Add the following lines to each configuration file:
Host github.com-account1
.....HostName github.com
.....User git
.....IdentityFile ~/.ssh/github_account1
Host gitlab.com-account1
.....HostName gitlab.com
.....User git
.....IdentityFile ~/.ssh/gitlab_account1
5- Replace account1 with your desired account name, and repeat steps 1-4 for each of your accounts.
6- Now, when you clone a repository from GitHub or GitLab, use the github.com-account1 or gitlab.com-account1 hostname instead of the default hostname. For example:
`git clone git@github.com-account1:username/repo.git`