美文网首页
github ssh提交遇到public key

github ssh提交遇到public key

作者: 卡卡罗忒 | 来源:发表于2019-12-04 17:38 被阅读0次

1. 检查SSH key是否已经存在

ls ~/.ssh/

进行检查 id_rsa.pub 是否存在,如果存在,就不用生成一个新的SSH key了,直接跳到下面的第3步。

2. 如果第1步中的SSH key不存在,生成一个新的SSH key

先:

cd /Users/wangjingxin/.ssh 

命令如下:

ssh-keygen -t rsa -b 2048 -C "your_email@example.com"

其中,your_email@example.com要修改成你的邮箱地址。
回车后输出如下:

Generating public/private rsa key pair. 
Enter file in which to save the key (/Users/wangjingxin/.ssh/id_rsa): 

直接回车,会将key保存到默认文件中。
接着会输出:

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

这两步是让你输入一个密码,以及确认密码,这个密码在你提交代码到Github时会用到【注意:记住这个密码,最简单的方式就是设置的和github账户登入密码一样,容易记住】
回车后就提示成功了:

Your identification has been saved in /Users/your_user_name/.ssh/id_rsa. 
Your public key has been saved in /Users/your_user_name/.ssh/id_rsa.pub. 
The key fingerprint is: 
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com 

到这一步,你会发现 /Users/wangjingxin/.ssh/id_rsa.pub 文件已经生成了。

3. 将ssh key添加到git

打开id_rsa.pub文件,复制里面的内容,然后粘贴到git中相关的位置中。
例如对于gitlab 来说:

4. 把ssh 添加到keychain中

这个时候如果去git clone代码,会让你输入密码,如果一个还好说,如果关联了很多的话,那就比较麻烦了,这个时候的解决方法就是添加到keychain中:

ssh-add -K /Users/youre_user_name/.ssh/id_rsa 

相关文章

网友评论

      本文标题:github ssh提交遇到public key

      本文链接:https://www.haomeiwen.com/subject/axblgctx.html