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 git@github.com:changchunhua2017/Shell-100-Days.git
   3af54d0..9074624  master -> master

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

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

小结:

github有两种连接方式:

1、clone with https

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

相关推荐
GoppViper1 小时前
golang学习笔记29——golang 中如何将 GitHub 最新提交的版本设置为 v1.0.0
笔记·git·后端·学习·golang·github·源代码管理
m0_464832363 小时前
Linux服务器上安装git lfs命令
git
贩卖纯净水.10 小时前
白月光git
git·github
爱吃瓜的猹z14 小时前
git reset 几点疑问
git·源代码管理
悟空201620 小时前
001、Git开发流程规范
git
Li小李同学Li20 小时前
git学习【持续更新中。。。】
git·学习·elasticsearch
晨春计1 天前
【git】
android·linux·git
念幽1 天前
Git常用命令
git
神技圈子1 天前
【git系列】git中的那些迷惑的术语以及概念详解
git
benben0441 天前
Photoshop使用方法大全
git