配置SSH连接Github

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenbetter1996/article/details/86664636

1. 本地生成公私钥

在Linux系统中,默认ssh密钥信息文件夹在 ~/.ssh隐藏文件夹下

ssh-keygen -t rsa -C "chgl16"

-t 是type秘钥类型,默认就是rsa
-C是Comment,秘钥注释

运行后可以在 ~/.ssh文件夹下看到公私钥

Generating public/private rsa key pair.
Enter file in which to save the key (/home/chgl16/.ssh/id_rsa): /home/chgl16/.ssh/id_rsa
Created directory '/home/chgl16/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/chgl16/.ssh/id_rsa.
Your public key has been saved in /home/chgl16/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:.....
The key's randomart image is:
...

公钥: ~/.ssh/id_rsa.pub
私钥: ~/.ssh/id_rsa
公钥是RSA 1024位,使用的时候会有个中间的公钥指纹,就是对公钥作MD5成128位32个十六机制数串。


2. Github账号中添加公钥

Settings -> SSH and GPG keys -> New SSH key
在这里插入图片描述

Title 可以随便写,仅是一个标注
Key 把生成的公钥贴上去

在这里插入图片描述
本地接受Github的公钥

ssh [email protected]
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
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 chgl16! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

添加到了 ~/.ssh/known_hosts 文件中


3. 使用

本地添加远程Github仓库的时候使用SSH,而不是HTTPS

[email protected]:chgl16/xxx.git

git remote add origin [email protected]:chgl16/xxx.git

猜你喜欢

转载自blog.csdn.net/chenbetter1996/article/details/86664636