SSH key是什么
SSH(Secure Shell)是一种加密的网络传输协议,可以在不安全的网络中为网络服务提供安全的传输环境。SSH 以非对称加密实现身份验证,通过C/S(client-server)模式来实现。
生成SSH Key
参考:生成ssh Key
$ ssh-keygen -t ed25519 -C "你要生成key的邮箱"
提示:如果系统不支持ed25519算法,则使用rsa算法
生成config
$ touch ~/.ssh/config
config中如下配置
#gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519_gitlab.pub
User user1@mail.com
#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519_github.pub
User user2@mail.com
将生成的私钥添加到ssh-agent的高速缓存中
$ ssh-add -K ~/.ssh/id_ed25519_gitlab
$ ssh-add -K ~/.ssh/id_ed25519_github
检测是否连接成功
$ ssh -T git@github.com //github的检测
$ ssh -T git@gitlab.com //gitlab的检测
邮箱配置
推荐全局配置常用邮箱
$ git config --global user.name "macondo"
$ git config --global user.email "macondos@mail.com"
在某个项目仓库地址局部配置不常用邮箱
$ git config --local user.name "macondo"
$ git config --local user.email "macondos@mail.com"