Git 配置SSH公钥
2019-10-05 本文已影响0人
Singularity_Lee
检查电脑上是否已经有SSH的Key
cd ~/.ssh
若出现下方提示直接创建新的Key
-bash: cd: /Users/singularity/.ssh: No such file or directory
ls -al ~/.ssh
创建新的Key
ssh-keygen -t rsa -C "邮箱地址"
出现下方提示即为成功,默认回车
即可
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/singularity/.ssh/id_rsa):
设置Key密码
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
添加Key至ssh-agent
eval "$(ssh-agent -s)"
*添加Key至rsa,并输入密码
ssh-add ~/.ssh/id_rsa
查看ssh公钥
cd ~/.ssh
cat id_rsa.pub
复制公钥至剪切板
pbcopy <id_rsa.pub
最后将剪切板中的公钥粘贴值GitLab或者GitHub中即可
![](https://img.haomeiwen.com/i1904687/85464eb44bf764fc.png)
更换秘钥或配置无密码
ssh-keygen -p
重新配置路径
Enter file in which the key is (/Users/singularity/.ssh/id_rsa):
将括号内的路径复制出去即可
,之后输入旧密码后一直回车确认即可设置为无密码,避免每次要输入密码才可使用
更新Git账号及密码
git config --global credential.helper osxkeychain
并在钥匙串
中删除互联网密码github.com
项,提交时重新输入账号密码即可
![](https://img.haomeiwen.com/i1904687/8484eeb3602d6ee1.png)