Git生成SSH密钥
使用Git推送代码到远程仓库的时候需要我们配置SSH连接,通过SSH key来验证推送人的身份是否有权限进行代码推送。可以先查看自己用户的主目录是否有.ssh文件夹。Linux环境下:
ls ~/.ssh
如果可以可以看到:
vincente@vincente-PC:~/.ssh$ ls ~/.ssh
id_rsa id_rsa.pub
那说明你已经存在密钥直接把id_rsa.pub
的内容复制到你远端Git仓库就可以进行代码推送了。
如果不存在那就进行下面操作:
默认你已经安装了Git客户端,Deepin下安装使用apt命令安装,Windows 自行百度下载
sudo apt-get install git
安装后,设置全局的用户名和邮箱
git config --global user.name "youre user name"
git config --global user.email "your email"
执行生成密钥命令
ssh-keygen -t rsa -C "your email"
一直回车就可以不需要设置密码:
vincente@vincente-PC:~/.ssh$ ssh-keygen -t rsa -C "3344758676qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vincente/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vincente/.ssh/id_rsa.
Your public key has been saved in /home/vincente/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:48+HA33Dw0mzkW8LxJcyh4jH471fWGuN9JVWtptTeJA 3344758676qq.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| . |
| o o oE.o|
| . = @ +++|
| S+ B @o+=|
| ...o @.+*B|
| .. o *oB+|
| oo o o..|
| oo .. |
+----[SHA256]-----+
这是在查看用户主目录就可以看到生成的一对秘钥(公钥和私钥),私钥存放在本地,公钥配置在需要ssh连接的远程服务端(比如Github、Gitee、公司的仓库私服)。
使用码云拉取代码测试,第一连接会提示你是否同意,输入yes即可。
vincente@vincente-PC:/data/home/vincente/Documents/learn$ git clone git@gitee.com:chsoul/spring_cloud.git
正克隆到 'spring_cloud'...
The authenticity of host 'gitee.com (212.64.62.183)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,212.64.62.183' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 11 (delta 3), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (11/11), 完成.
处理 delta 中: 100% (3/3), 完成.
这是在查看主目录下的.ssh文件夹会发现多了一个文件
vincente@vincente-PC:/data/home/vincente/Documents/learn$ ls ~/.ssh/
id_rsa id_rsa.pub known_hosts
known_hosts存放的内容为可信任域地址。
本文来自博客园,作者:星光Starsray,转载请注明原文链接:https://www.cnblogs.com/starsray/p/13868392.html