博主现在也是小白,所以废话不多用,直接来说重点,网上的教程其实并不少,随手一搜就能找到一大堆,所以博主也是把这些步骤进行整理并简单化一些
Linux设置方法:
1、注册Github账号,并登陆,再创建一个仓库,点击进入github官网

2、打开Linux系统终端,输入以下命令生成 SSH key

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥

3、在打印信息中,Enter file in Which to save the key表示选择默认的目录,我们直接回车,表示默认,Enter passphrase (empty for no passphrase) 和 Enter same passphrase again表示输入密码和确认密码,为了方便连接我们也直接回车(默认),其他同样默认

配置ssh 公钥 ssh 添加公钥_git_02

4、输入以下命令切换到刚才默认创建的 ssh 目录

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_03


5、输入 ls 命令 可以看到里面有两个文件:id_rsa为私钥文件,id_rsa.pub为公钥文件

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_04


6、接下来复制 id_rsa.pub 公钥文件的内容,可以打开该文件进行复制,在这我们用 cat 命令把内容打印在终端上进行查看并复制

配置ssh 公钥 ssh 添加公钥_git_05


7、打开 github – 点击头像 – 找到 setting选项点击打开,进入到setting页面,找到 SSH and GPG keys选项

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_06


配置ssh 公钥 ssh 添加公钥_github_07

8、点击 New SSH key ,在Title一栏输入 key名称(随意填写)在 key 栏 把 刚才复制的 公钥内容复制进去,然后点击 add SSH key,然后就会看到刚才我们添加的 SSH key

配置ssh 公钥 ssh 添加公钥_git_08


配置ssh 公钥 ssh 添加公钥_git_09

9、安装 git ,如果已经安装完请跳过,

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_10

10、配置git用户名,如果像设置全局生效,需要添加 --global 参数:git config --global user.name ‘你的名字’(可随意写), git config --global user.email ‘你的邮箱’ (建议写github的邮箱)

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_11


配置ssh 公钥 ssh 添加公钥_git_12


11、OK,Linux和github配置完了,接下来我们测试一下SSH key是否设置成功,终端输入命令:$ ssh -T git@github.com,根据提示信息 输入 yes 确定连接,如果看到 Hi xxxx! You’ve successfully authenticated, but GitHub does not provide shell access.说明我们设置成功,

配置ssh 公钥 ssh 添加公钥_git_13


12、接下来我们使用 git 把github上的项目看能否克隆下来,打开github的一个仓库,点击Clone or download — Use SSH — 点击复制链接

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_14


配置ssh 公钥 ssh 添加公钥_Bash_15


13、打开终端 — 输入 git clone ’ git 你要clone的链接’,克隆仓库到本地,克隆完成后可以用 ls 命令查看内容

配置ssh 公钥 ssh 添加公钥_git_16

Windows设置方法:

1、windows最好先安装好 git, 安装完之后,在桌面右键点击,Git GUI Here, Git Bash Here,点击Git Bash Here打开 终端 ,按照上面Linux的设置方法即可

配置ssh 公钥 ssh 添加公钥_github_17

配置ssh 公钥 ssh 添加公钥_配置ssh 公钥_18