Create a gist now

Instantly share code, notes, and snippets.

@yisibl /git-key.md
Last active May 21, 2018

What would you like to do?
如何创建 Git 公钥

如何创建公钥

  1. 首先启动一个Git Bash窗口(非Windows用户直接打开终端)

  2. 执行:

    cd ~/.ssh

    如果返回“… No such file or directory”,说明没有生成过SSH Key,直接进入第4步。否则进入第3步备份!

  3. 备份:

    mkdir key_backup mv id_isa* key_backup

  4. 生成新的Key:(引号内的内容替换为你自己的邮箱)

    ssh-keygen -t rsa -C "your_email@youremail.com"

输出显示:

>Generating public/private rsa key pair. Enter file in which to save the key 
(/Users/your_user_directory/.ssh/id_rsa):<press enter>

直接回车,不要修改默认路劲。

>Enter passphrase (empty for no passphrase):<enter a passphrase>
Enter same passphrase again:<enter passphrase again>

设置一个密码短语,在每次远程操作之前会要求输入密码短语!闲麻烦可以直接回车,不设置。

  1. 成功:

    Your identification has been saved in /Users/your_user_directory/.ssh/id_rsa. Your public key has been saved in /Users/your_user_directory/.ssh/id_rsa.pub. The key fingerprint is: ... ...

  2. 提交公钥:

    6.1 找到.ssh文件夹,用文本编辑器打开“id_rsa.pub”文件,复制内容到剪贴板。

    6.2 打开 https://github.com/settings/ssh ,点击 Add SSH Key 按钮,粘贴进去保存即可。

@feifeihappy

This comment has been minimized.

Show comment Hide comment
@feifeihappy

feifeihappy Aug 28, 2015

谢谢

谢谢

@sunliying

This comment has been minimized.

Show comment Hide comment
@sunliying

sunliying Jan 17, 2016

谢谢,但是我生成之后在提交时还会问我的name和password,而不是用秘钥,这是为什么

谢谢,但是我生成之后在提交时还会问我的name和password,而不是用秘钥,这是为什么

@weaming

This comment has been minimized.

Show comment Hide comment
@weaming

weaming Apr 20, 2016

@sunliying 需要用ssh, 而不是https

weaming commented Apr 20, 2016

@sunliying 需要用ssh, 而不是https

@FannieGirl

This comment has been minimized.

Show comment Hide comment
@FannieGirl

FannieGirl Sep 9, 2016

谢谢

谢谢

@githubhao0705

This comment has been minimized.

Show comment Hide comment
@githubhao0705

githubhao0705 Mar 11, 2017

感谢

感谢

@IronLu233

This comment has been minimized.

Show comment Hide comment
@IronLu233

IronLu233 Mar 17, 2017

Thanks a lot!

Thanks a lot!

@gumuyueying

This comment has been minimized.

Show comment Hide comment
@gumuyueying

gumuyueying Nov 19, 2017

Thank you!
A typo: “闲麻烦” -> “嫌麻烦”。

Thank you!
A typo: “闲麻烦” -> “嫌麻烦”。

@nstflecher

This comment has been minimized.

Show comment Hide comment
@nstflecher

nstflecher Mar 21, 2018

感谢大大

感谢大大

@Z-Shoushou

This comment has been minimized.

Show comment Hide comment
@Z-Shoushou

Z-Shoushou Mar 27, 2018

感谢大佬

感谢大佬

@xue7106211

This comment has been minimized.

Show comment Hide comment
@xue7106211

xue7106211 Mar 31, 2018

感谢~

感谢~

@thegreatestkingofbunny

This comment has been minimized.

Show comment Hide comment
@thegreatestkingofbunny

thegreatestkingofbunny Apr 11, 2018

谢谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment