GIT连接Github


img

一、Git连接github:

先配置 ssh

1. 设置Git的user name和email:
git config --global user.name "用户名"
git config --global user.email "注册邮箱"

2. 生成SSH密钥:

(1). 生成新的Key:ssh-keygen -t rsa -C "注册邮箱"

root@H2o2:~# ssh-keygen -t rsa -C "注册邮箱"

输出:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):     # 直接回车,不要修改默认路径
Enter passphrase (empty for no passphrase):        # 设置一个密码短语,在每次远程操作之前会要求输入密码短语!闲麻烦可以直接回车,不设置
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.  # 成功
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
...

3. 提交公钥

打开.ssh文件,这个文件是隐藏的,需要查看隐藏文件,以Linux为例:

root@H2o2:~# cd ~/.ssh
root@H2o2:~/.ssh# ls
id_rsa  id_rsa.pub  known_hosts    

id_rsa.pub 为公钥,用编辑器打开,复制里面的公钥

root@H2o2:~/.ssh# cat ./id_rsa.pub       # 查看 id_rsa.pub 的内容
...

打开Github.com,找到Settings--->SSH and GPG keys--->New SSH KeyTitle随便写,id_rsa.pub内容粘贴到Key

4.连接测试

ssh git@github.com

root@H2o2:~# ssh git@github.com

The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:显示你的key.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

# 密钥名非 id_rsa 使用选项 -i 
> ssh git@github.com -i ~/.ssh/id_github_rsa
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容