关于程序员:配置多个SSHKey

4次阅读

共计 1063 个字符,预计需要花费 3 分钟才能阅读完成。

配置多平台 SSH-Key

进入零碎 ssh 目录

cd ~/.ssh

生成 github 密钥

ssh-keygen -t rsa -C "your_mail@example.com" -f github_rsa

回车确认,直到实现。其余账号操作相似

生成 gitlab 密钥

ssh-keygen -t rsa -C "your_mail@example.com" -f gitlab_rsa

生成 gitee 密钥

ssh-keygen -t rsa -C "your_mail@example.com" -f gitee_rsa

查看公钥

// 查看 github 公钥
cat github_rsa.pub
// 查看 gitlab 公钥
cat gitlab_rsa.pub
// 查看 gitee 公钥
cat github_rsa.pub

将失去的公钥别离复制到对应账号 SSH 设置中

增加 config 文件(若无)

touch config //mac linux,windows 举荐应用 git bash

为 config 文件增加如下内容

# github.com
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa

# gitlab.company.com
Host gitlab.company.com # 此域名端口默认 22,如果为 122 端口,需设置 gitlab.company.com:122
HostName gitlab.company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_rsa

# gitee.com
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_rsa

测试

// test github ssh-key
ssh -T git@github.com
// test gitlab ssh-key
ssh -T git@gitlab.company.com
// test gitee ssh-key
ssh -T git@gitee.com

胜利

输入内容如下时,配置胜利

Hi YK-Unit! You’ve successfully authenticated, but GitHub does not provide shell access.

此输入内容为测试 github ssh-key,其余账号测试内容相似

揭示

Windows 系统命令终端举荐应用 git bash。

正文完
 0