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

相关推荐
high20114 小时前
【Git】-- 版本说明
git
kaixin_learn_qt_ing5 小时前
git clone
git
sin22015 小时前
git stash
git
喝鸡汤5 小时前
一起学Git【第二节:创建版本库】
git
慢慢成长的码农5 小时前
git 同步分支操作
git
sin22015 小时前
git推送本地仓库到远程(Gitee)
git·gitee
丁总学Java7 小时前
git branch -r(--remotes )显示你本地仓库知道的所有 远程分支 的列表
git
yylの博客10 小时前
Windows通过git-bash安装zsh
windows·git·bash·zsh
丁总学Java10 小时前
(Z Shell)zsh: no matches found: ? 使用单引号包裹
git·zsh
萌狼蓝天11 小时前
【NAS】绿联NAS+极狐Gitlab+1Panel
git