您的位置:首页 > 编程语言

Git 和 SSH 密钥连接 Github

2014-07-19 11:38 375 查看
来自:http://blog.csdn.net/wangeen/article/details/9021301

2013-06-04 13:10 494人阅读 评论(0) 收藏 举报

目录(?)[+]

Github 是互联网上最流行的 Git 托管服务商,对于开源的程序免费。

要使用它,首先需注册 Github 帐号,然后本地安装 Git,我觉得编译安装和通过 apt-get 方式安装都可以,这两个步骤本贴板就略去了。

2012-03-04 23:164209 次浏览#Git#Github关注1


 生成SSHKeys


生成 SSH Keys

以 Linux Mint (Ubuntu) 为例,需要用到 ssh-keygen 命令:

<span class="pln" style="color: rgb(0, 0, 0);">ssh</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">keygen </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">t rsa </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">C </span><span class="str" style="color: rgb(0, 136, 0);">"xian**@gmail.com"</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">f </span><span class="pun" style="color: rgb(102, 102, 0);">~</span><span class="str" style="color: rgb(0, 136, 0);">/.ssh/</span><span class="pln" style="color: rgb(0, 0, 0);">csser</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">github</span>


简单介绍下参数含义:

-t 指定密钥类型,默认即 rsa ,可以省略

-C 设置注释文字,比如你的邮箱

-f 指定密钥文件存储文件名,会生成 csser-github 和 csser-github.pub 两个密钥文件

回车后,遇到提示输入 yes 即可,剩下一路回车,密钥文件就在指定路径下生成了。

1 条评论一回•2012-03-04
23:20


 将SSH公钥添加到Github


将 SSH 公钥添加到 Github

登录 Github 帐号,找到帐号设置 -> 
SSH Keys


点击 
Add New SSH Key


将本地生成的公钥文件(csser-github.pub)中的文字全选复制到 
key
 栏,点击 
add
key
 保存。

1 条评论一回•2012-03-04
23:19


 本地添加SSH别名


本地添加 SSH 别名

如果本机有其它密钥,连接 github 时可能不会自动使用刚生成的密钥,需要设置别名:

<span class="pln" style="color: rgb(0, 0, 0);">$ sudo vi </span><span class="pun" style="color: rgb(102, 102, 0);">~</span><span class="str" style="color: rgb(0, 136, 0);">/.ssh/</span><span class="pln" style="color: rgb(0, 0, 0);">config</span>
加入类似的一段代码:

<span class="pln" style="color: rgb(0, 0, 0);">host csser</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">github
user git
hostname github</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">com
port </span><span class="lit" style="color: rgb(0, 102, 102);">22</span><span class="pln" style="color: rgb(0, 0, 0);">
identityfile </span><span class="pun" style="color: rgb(102, 102, 0);">~</span><span class="str" style="color: rgb(0, 136, 0);">/.ssh/</span><span class="pln" style="color: rgb(0, 0, 0);">csser</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">github</span>
保存退出。

3 条评论一回•2012-03-04
23:18


 测试连接


测试连接

<span class="pln" style="color: rgb(0, 0, 0);">$ ssh </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">T csser</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">github
</span><span class="typ" style="color: rgb(102, 0, 102);">Hi</span><span class="pln" style="color: rgb(0, 0, 0);"> csser</span><span class="pun" style="color: rgb(102, 102, 0);">!</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">You</span><span class="str" style="color: rgb(0, 136, 0);">'ve successfully authenticated, but GitHub does not provide shell access.</span>
表示设置的 SSH Keys 认证通过,但 Github 不提供 shell 访问。

此时就可以正常使用 Github 了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: