(Git 学习)Git SSH Key 创建步骤

时间:2023-03-09 14:55:33
(Git 学习)Git SSH Key 创建步骤

首先感谢segmentfalut上的朋友对我帮助。

首先:查看你是否有../ssh 这个文件;
怎么查看;找到你的git安装目录,在安装目录下查看是否./ssh,
以我的为例:

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤
在C盘/Users/11/下面;

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤
看到没有.ssh文件;

如果你已经有了这个文件,可以跳过直接区文章末尾;
开始创建:
(用 git bash Here 进行下面的操作)

第一步配置你的用户信息:
命令:
git config --global user.name "Xyd1995" //配置你的账户名字
git config --global user.email "752136881@qq.com" //配置你的创建github账户的邮箱; 查看已经配置好的用户信息:
git config user.name
git config user.email (Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

这里需要主要 git config --global user.name后面要有空格!!

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

生成SSH key 
命令:ssh-keygen -t rsa -C "752136681@qq.com"
后面填写你得邮箱!!!

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

这里我发现用cmd 提示 ssh不是命令~~~换用 git bash Here 如果你已经安装了,在桌面右键就会看见

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

他会提示你输入三个选项需要填写,我也不是太懂。。
第一个是创建这个密钥的文件名称;
第二个是创建一个密码;
第三个是确认这个密码;
百度是:创建一个密码;远程时需要输入这个 密码;我就不填写了。全部回车;

这个就是输入你创建的ssh key的文件名称;默认是id_rsa,如果你回车它就默认在改路径下创建名为id_rsa的文件

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

创建好了之后,回到我们前面查找的目录,看有没有.ssh文件夹

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

哎,,,,有了~~~~
./ssh文件下,有一个id_rsa 文件,我们就是需要这个。

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

登录github 填写这个ssh key

进入个人设置选项,找到setting进入,找到SSH and GPG keys

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

打开 ssh and GPG keys

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

测试一下是否可以链接:
命令:ssh -T git@github.com

泡脚凤爪~~~我的报错了 - -.

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤
提示:链接到主机git@github.com端口20超时~~~
百度之后,可能时端口被占用;
解决办法:
在./ssh 下找到congfig文件,如果没有就创建一个

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

在config文件中复制下面代码:

Host github.com

User git

Hostname ssh.github.com

PreferredAuthentications publickey

IdentityFile ~/.ssh/id_rsa

Port 443

然后在执行 
ssh -T git@github.com 查看是否可以链接;

回车即可,意思百度吧。

(Git 学习)Git SSH Key 创建步骤(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

(Git 学习)Git SSH Key 创建步骤

链接成功。 ssh key 验证成功,你可以本地仓库上传远程仓库了~