怎么同时配置多个代码托管网站的SSH,比如gitee、github?简单几步就搞定,不废话!!!!!
一:生成SSH秘钥
- 生成秘钥命令如下(注释会出现在
.pub文件中,一般可使用邮箱作为注释内容。)
ssh-keygen -t ed25519 -C "<注释内容>"
- 选择SSH秘钥生成路径:默认路径如下,可以改个自己喜欢的文件名
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
- 设置一个密钥口令。(建议为空)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
- 一路回车,完成秘钥的创建
二:拷贝秘钥
- 打开
./.ssh/xxxx.pub文件,全部复制
三:在码云、github等网站配置公钥
- 粘贴好就行
四:怎么同时配置多个网站的SSH?(划重点)
-
在上边SSH秘钥生成路径时,改个区分不同平台的名字,比如
id_gitee或者id_github -
配置
~/.ssh/config文件,配置参考如下
# 码云
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_gitee
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_github
# codeup
Host codeup.aliyun.com
HostName codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_codeup
- just so easy