github 添加密钥实现无密码操作

csdn 写博客方面,不过想存储一些文件及目录结构就比较麻烦了,所以想一边玩csdn,一边玩github 毕竟github用户基数特别广,混个眼熟也好

我这边在git push的时候经常需要重复的输入密码,觉得有点烦,所以想上传自己的公钥上去,免去重复的动作。下面开始


一、生成ssh密钥对

当然上传之前肯定要自己先生成ssh key了,windows的用户可以下载xshell之类的工具来生成,我这边linux就直接输命令了

ssh-keygen -t rsa # 一直回车下去,不输入密码


二、查看公钥

密钥对生成完成后存放于当前用户 ~/.ssh 目录中,查看 id_rsa.pub

[root@centos7-202 ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2u40rO6mxw+9MQ2EDhX7W0r7+6YC6KMr7V89SH1Qzeuxr4YJvnaaTULw1dQaLuiuXuOasT6shgR/Dbfl3n2FAP3jx/+e0LUIQDi4W0C6M9raaod1B9mhAzZ3Rd5oilM8pPn/LSC9tb3zqDw/vQXtJeSGZpf6VM80SsufGxDaQEkLGvB9YMqY4O41eZDo5yX3CRrX4gadjVS9X0DCTA1QEeRg9snmDYK1Y4nbHUtoVHsXsfWcwK7rZIQKVdyZvoZv9tpL7IdcKmwbwbF/XQaEZJMpwRZB4SjYTV6kaZraVX3iLpSTpVSBRSyjxpbZZt8zeg0FPabIsipmvx2G6SqeZ root@centos7-202
[root@centos7-202 ~]#


三、上传公钥

将公钥内容复制并上传于github

https://github.com 打开并登录,接着点击右上角头像,并且单击 setting

这里写图片描述

接着点击 SSH and GPG keys,我们只需要添加 SSH key 即可

这里写图片描述

将刚才查看到的公钥复制进去,并且单击 add ssh key,github会提示你输入当前用户的密码,之后即可保存

这里写图片描述

这里写图片描述


四、验证

上传公钥之后我们在系统操作一些原本需要输入密码的事,在这之前,我们先 clone 一个project下来,记得要clone ssh协议的项目,https不支持的哦

这里写图片描述

先把项目 clone 下来

[root@centos7-202 ~]# git clone git@github.com:wangleistorage/test.git
Cloning into 'test'...
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
remote: Counting objects: 71, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 71 (delta 24), reused 55 (delta 11), pack-reused 0
Receiving objects: 100% (71/71), 7.30 KiB | 0 bytes/s, done.
Resolving deltas: 100% (24/24), done.
[root@centos7-202 ~]# 

接着编辑项目,并且push到github

从下面的命令中可以看出

  • 1、我先 git rm test.txt 删除本地仓库中的文件
  • 2、接着 git commit 提交
  • 3、最后 git push 上传到github中
  • 4、整个过程都没有提示我输入密码
[root@centos7-202 test]# git rm test.txt 
rm 'test.txt'
[root@centos7-202 test]# git commit -m 'delete test.txt'
[master a84df15] delete test.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 test.txt
[root@centos7-202 test]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 221 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local objects.
To git@github.com:wangleistorage/test.git
   41e60fe..a84df15  master -> master
[root@centos7-202 test]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值