美文网首页
mac上生成github的sshkey(公钥秘钥)

mac上生成github的sshkey(公钥秘钥)

作者: 我是我自己的 | 来源:发表于2018-08-01 17:16 被阅读0次

1、打开终端输入如下命令:

ssh-keygen -t rsa -C "xxxx@qq.com"

其中1845...为注册github的邮箱

2、出现如下提示时按回车键确认

Enter file in which to save the key (/Users/xxxx/.ssh/id_rsa):

3、出现如下提示时,输入密码:

Enter passphrase (empty for no passphrase): 

4、出现如下提示时,再次输入密码:

Enter same passphrase again: 

5、出现如下提示时,表明秘钥生成成功

Your identification has been saved in /Users/liuboying/.ssh/id_rsa.

Your public key has been saved in /Users/liuboying/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:pOE18kCMOhl56E1gg45EFcUO9evX6tODe6VuHbqHa5g xxx@qq.com

6、进入~/.ssh目录,打开id_rsa.pub文件

cd ~/.ssh

vim id_rsa

将id_rsa.pub文件的内容copy出来

7、打开github的个人设置页,点击左侧的SSH and GPG keys,点击“New ssh key”按钮,并将copy的id_rsa文件内容写入输入框后保存,如下图

8、配置多个账号

cd ~/.ssh

vim config

并在编辑器中输入一下内容:

Host github.con

HostName github.com

User liuboying

IdentityFile /Users/xxxx/.ssh/id_rsa_github_qq (注意此处为id_rsa_github_qq的绝对路径。)

如果有多个账号,则将以上4条内容增加在config文件中,并将相应信息改成其他账号对应的信息(经测试,在我的电脑上IdentityFile路径中的文件名称必须为id_rsa才能生效,因此无法实现多个秘钥。)

注意:1-7步生成的id_rsa和id_rsa.pub,在需要生成多个key的时候,需要将生成的这2个文件重命名,以免再次生成的时候被覆盖。

相关文章

网友评论

      本文标题:mac上生成github的sshkey(公钥秘钥)

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