Git学习笔记5

GitHub免密Push:

免密Push其实就是利用了SSH免密登录的原理:

1)在本地产生空密钥对;

2)本地保留私钥,把公钥给对方;

3)实现本地到远程的免密;

在开发者电脑上产生一对空密钥对:

bash 复制代码
[root@git-server ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:uEQ9J8U/yZl39Oa7hjnAMIUiu4W025djck/l/ILOLe0 root@git-server
The key's randomart image is:
+---[RSA 2048]----+
|         .o      |
|     o o o..    .|
|    . * = oo + ..|
|     = o *  B.. +|
|      B S = +o + |
|     + + * + o  .|
|      . = + + + .|
|          .+.* + |
|          .ooE+..|
+----[SHA256]-----+

其中说公钥已经被存放在/root/.ssh/id_rsa.pub。

将这个公钥文件的内容复制到github需要Settings的地方。

然后进行下测试:

获取ssh克隆方式的地址:

开发者再次将git clone项目到本地:

这次使用的是git@开头的这个地址。在这个过程中没有要求输入账号密码。

再准备一个新的代码文件,添加并提交:

bash 复制代码
[root@git-server Shell-100-Days]# echo "haha" > haha.py
[root@git-server Shell-100-Days]# ll
total 16
-rw-r--r-- 1 root root 5 Sep 19 21:26 1.py
-rw-r--r-- 1 root root 5 Sep 19 21:26 2.py
-rw-r--r-- 1 root root 5 Sep 19 21:27 haha.py
-rw-r--r-- 1 root root 5 Sep 19 21:26 README.md
[root@git-server Shell-100-Days]# git add haha.py
[root@git-server Shell-100-Days]# git commit -m "Commit haha.py"
[master 9074624] Commit haha.py
 1 file changed, 1 insertion(+)
 create mode 100644 haha.py
[root@git-server Shell-100-Days]# 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), 237 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: To [email protected]:changchunhua2017/Shell-100-Days.git
   3af54d0..9074624  master -> master

这次再使用git push就会发现不需要输入账号密码了。

再在github上检查验证下文件:

小结:

github有两种连接方式:

1、clone with https

2)clone with ssh(通过ssh免密密钥实现对实现免密push。)

相关推荐
Stack_guigui29 分钟前
git连接本地仓库以及gitee
git·gitee
火车叼位32 分钟前
Git 精准移植代码:cherry-pick 简单说明
前端·git
Cynthia-石头4 小时前
Git Github Gitee GitLab
git·gitee·github
ak啊18 小时前
Git 撤销操作完全指南:从工作区到远程仓库的救赎之路
git
小_路20 小时前
git 常用命令
git
Dontla1 天前
git引用概念(git reference,git ref)(简化对复杂SHA-1哈希值的管理)(分支引用、标签引用、HEAD引用、远程引用、特殊引用)
git·算法·哈希算法
枫叶落雨2221 天前
Git 使用规范指南
git
德育处主任2 天前
聚沙成塔,三步成书:GitBook极简入门教程
前端·git·电子书
m0_635647482 天前
git管理github上的repository
git·github
Jiude2 天前
基于开源项目开发公司项目,如何同步开源仓库的最新更新(以vben为例)
git·开源·github