1、生成ssh秘钥
gitlab: ssh-keygen -t rsa -C"youemail@mail.com" -f ~/.ssh/gitlab_id-rsa github: ssh-keygen -t rsa -C"youemail@mail.com" -f ~/.ssh/github_id-rsa
执行后一直回车就行,因为指定了秘钥名称不用担心会相互覆盖。
这里每条命令会生成 github_id-rsa 私有和 github_id-rsa.pub 公有两个秘钥
2、创建文件config
#github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_id_rsa // 这里路径与保存的路径一致
[alias] // 常见命令缩写
co = checkout
ci = commit
br = branch
st = status
3、github上配置ssh
vim github_id_rsa.pub
得到公有秘钥,复制后添加到github的SSH Keys里面
4、测试连接
ssh -T git@github.com
5、gitconfig配置
git config 常用配置选项 git config -e 编辑配置文件 git config --local -e 编辑仓库级别配置文件 git config --global -e 编辑用户级别配置文件 git config --system -e 编辑系统级别配置文件 git config 添加配置项目 git config --global user.email “you@example.com” git config --global user.name “Your Name”
6、一些错误
# 权限开的太高666,更改config的权限为 600即可 Bad owner or permissions on .ssh/config