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。)

相关推荐
泰勒朗斯5 小时前
如何在新机器上设置github完成内容git push
git·github
小妖66610 小时前
git branch -a 还有一些已经删除了的分支
git
&Sinnt&1 天前
Git 版本控制完全指南:从入门到精通
git·后端
Tiny2141 天前
多人协同开发时Git使用命令
git
WebGirl1 天前
代码Revert后再次Merge会丢失的问题
git
小皮侠1 天前
nginx的使用
java·运维·服务器·前端·git·nginx·github
HalukiSan1 天前
如何提交PR
git·gitlab·github
爱莉希雅&&&2 天前
shell编程之awk命令详解
linux·服务器·git
baiyu332 天前
成为git砖家(12): 看懂git合并分支时冲突提示符
git
wu_aceo2 天前
将本地项目提交到Gitee
git·gitee·提交·本地提交·上传git