git配置ssh秘钥(公钥以及私钥)linux
2024-09-04 03:18:27
本文默认已经安装git,并有github或者gitlab账号
git在linux下安装参考:https://www.cnblogs.com/lz0925/p/10791147.html
在Linux中配置ssh密钥,在Git中使用SSH协议访问Github,使用 SSH 协议, 您可以连接并验证远程服务器和服务。在每次访问时连接到 GitHub 而不提供用户名或密码。
第一步:检查是否存在SSH秘钥
ls -al ~/.ssh
如果显示 cannot access /root/.ssh: No such file or directory 表示目录不存在,ssh不存在,如果存在也可以继续执行第二步
第二步:生成ssh-key 密钥对,包含:公钥、私钥
ssh-keygen -t rsa -C "271xxxxxx@qq.com"
第一次回车,然后会让你输入两遍密码,可以输个自己容易记住的 也可以不输入直接一路回车到底,出现下面的情况就成功了
The key's randomart image is:
+---[RSA ]----+
|.=oB+o. |
|oo% ooo . |
| =.* o+B. |
| + =.E+= |
| . + + +S* |
| . . . * O |
| . + * . |
| o o |
| o |
+----[SHA256]-----+
秘钥路径在刚刚输入密码后会告诉你,注意检查命令行,一般路径如下在用户目录下的.ssh目录
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
第三步:添加ssh-key私钥到 ssh-agent
1、首先确保ssh-agent正常工作
[root@ACA832F0 ~]# eval $(ssh-agent -s)
Agent pid
2、直接将私钥id_rsa添加到ssh代理中,跟windows不同的是不需要修改后缀为.ppk
[root@ACA832F0 ~]# ssh-add ~/.ssh/id_rsa
Enter passphrase for /root/.ssh/id_rsa:
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
第四步:将公钥id_rsa.pub添加到你的github或者gitlab等仓库中,
打开公钥文件复制全文
vim /root/.ssh/id_rsa.pub
使用邮箱登录仓库,用户setting -> SSH key 将公钥粘贴进去,起个容易识别的名字 title
第五步:验证
ssh -T git@172.168.50.41
出现类似下面的情况,OK
The authenticity of host '172.168.50.41 (172.168.50.41)' can't be established.
ECDSA key fingerprint is SHA256:28OQAVeipIe3M4oro+tTp+ExT5+z8+1PbE3ArCiTjYs.
ECDSA key fingerprint is MD5:0c:3d:e9:::e9:aa:c1::cc::0e:f7:b6::b3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.168.50.41' (ECDSA) to the list of known hosts.
Welcome to GitLab, @lizh
第六步:使用,clone代码
[root@ACA832F0 project]# git clone ssh://git@192.168.50.49:22/backs/www.facility.com.git
Cloning into 'facility.klagri.com.cn'...
remote: Enumerating objects: , done.
remote: Counting objects: % (/), done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), 15.31 MiB | 33.01 MiB/s, done.
Resolving deltas: % (/), done.
最新文章
- Android NDK 初探,生成so文件以及调用so文件方法
- c语言中gets ,getschar 和fgets 的用法及三者之间的差别,还有scanf
- C#之数据分页
- Apache Spark源码走读之22 -- 浅谈mllib中线性回归的算法实现
- 解决问题 “You don't have permission to access /index.html on this server.”
- Win32 SDK程序创建一些控件(简单调用InitCommonControlsEx,并指定ICC_LISTVIEW_CLASSES控件就可以了)
- PHP代理访问网络资源
- Tomcat中部署web应用 ---- Dubbo服务消费者Web应用war包的部署
- CSS3 box-shadow 内外阴影效果
- include指令和<;jsp:include>;动作标识区别:--不明觉厉 先收藏
- Linux-入门配置jdk,tomcat,mysql
- Swift 命令行输入输出
- Package 设计3:数据源的提取和使用暂存
- 51 nod 1046 A^B Mod C
- <;iOS>;一个开发中值得注意的细节
- [转载] 我的WafBypass之道(SQL注入篇)
- 轻量级网络 - PVANet & SuffleNet
- 无法修改SQL Server 服务名称
- ZROI2018提高day4t3
- Angular2使用ng2-file-upload上传文件