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

相关推荐
MrLi01041 小时前
在git中同时配置gitcode和github访问权限
git·github·gitcode
越来越无动于衷1 小时前
Git 团队协作完全指南:从基础到高级应用
git
小怪兽会微笑1 小时前
如何上传github(解决git的时候输入正确的账号密码,但提示认证失败)
git·github
Komorebi_999914 小时前
Git常用指令
git·web
一小池勺16 小时前
🚀 Git 如何让文件存在于远程仓库却不被本地追踪?
git·github
五月高高18 小时前
Idea使用git不提示账号密码登录,而是输入token问题解决
git
魏 无羡18 小时前
idea实现git版本回退的常见场景
java·git·intellij-idea
ergevv21 小时前
不同场景下git指令的搭配
git·源代码管理·代码
不了_谢谢1 天前
项目仓库文件太大怎么清理?如何清理git仓库大文件记录?
git