Last updated on Jun 10, 2022

我们在实际生产过程可能会遇到需要在一台电脑上配置不同 SSH Key 的情况。例如我们可能需要同时使用 GitHub 以及 GitLab 的情况,这时我们就需要配置不同的 SSH Key 了

Modern

使用 1Passwrod 管理 SSH Key

创建 SSH Key

  1. 点击创建项目(选择 SSH Key)
  2. 生成 New SSH Key(推荐使用 Ed25519)

Untitled

添加 SSH Key

  1. 在 GitHub/Gitlab 中选择 SSH Key
  2. 使用 1Password 自动填充公钥

Untitled

配置 Config 文件

增加 config 配置文件(若有则直接编辑,无则创建。路径 ~/.ssh/config

# 创建 config 配置文件
$ touch ~/.ssh/config

添加以下内容:

Host *
	IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"

测试

# 测试 SSH 连接
$ ssh -T [email protected]
$ ssh -T [email protected]_company.com

Untitled

只需要一份 SSH Key,可在不同的客户端使用

Legacy

创建 SSH Key

.pub 后缀的文件就是公钥,另一个文件则是私钥。