本地多处理个SSH key

一、创建方式

创建默认id_rsa:ssh-keygen -t rsa -C '邮箱地址'

创建特殊需要的ssh key命名例如test,创建方式为ssh-keygen -t rsa -C '邮箱地址' -f ~/.ssh/test

二、设置配置

在目~/.ssh下创建config文件,里面填充内容实例:

# 默认 id_rsa
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

# 特殊需要 key 名称为test
Host test.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/test

三、添加到github

此处就正常的在 github-> settings->SSH And GPG keys中添加就好

四、使用

1. 拉取代码

默认id_rsa:

git clone [email protected]:仓库名称 #例如:[email protected]:name/name.github.io.git

特殊test

git clone [email protected]:仓库名称 #例如:[email protected]:name/name.github.io.git

2. 本地关联远程

默认id_rsa:

git remote add origin [email protected]:仓库名称 #例如:[email protected]:name/name.github.io.git

特殊test

git remote add origin [email protected]:仓库名称 #例如:[email protected]:name/name.github.io.git

你可能感兴趣的:(本地多处理个SSH key)