惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
Cloudbric
Cloudbric
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
爱范儿
爱范儿
The Cloudflare Blog
腾讯CDC
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
C
Check Point Blog
Schneier on Security
Schneier on Security
S
Schneier on Security
J
Java Code Geeks
B
Blog RSS Feed
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
A
About on SuperTechFans
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
A
Arctic Wolf
S
Secure Thoughts
P
Palo Alto Networks Blog
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 三生石上(FineUI控件)
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
U
Unit 42
I
InfoQ
D
DataBreaches.Net
P
Privacy International News Feed
T
Troy Hunt's Blog
博客园 - 叶小钗
T
Threatpost
博客园 - Franky
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
www.infosecurity-magazine.com
www.infosecurity-magazine.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cisco Blogs

步步走

mac 环境变量与 shell · 步步走 如何反编译微信小程序 · 步步走 mac 终端命令大全 · 步步走 深入学习 TypeScript 类型体操 · 步步走 微前端的几种架构介绍 · 步步走 从 ESLint 开始,说透我如何在团队项目中基于 Vue 做代码校验 · 步步走 死磕 36 个 JS 手写题(搞懂后,提升真的大) · 步步走 1.5 万字 CSS 基础拾遗(核心知识、常用需求) · 步步走 为你的网站加上 WebP 格式的图片吧 · 步步走 让人爱不释手的 JS 扩展操作符 13 用 · 步步走 6 分钟了解 HTTP 发展史 · 步步走 Resourse Hints 知多少 · 步步走 探究网页资源究竟是如何阻塞浏览器加载的 · 步步走 很多人知道 Web Storage,但是你清楚 Cookie 嘛 · 步步走 浏览器专题之缓存篇 · 步步走 从输入 URL 到页面显示发生了什么 · 步步走 浏览器专题之事件机制 · 步步走 浏览器专题之安全篇 · 步步走 「建议收藏」送你一份精心总结的3万字ES6实用指南(全) · 步步走
git clone 的时候如何通过 SSH 链接来下载远程项目 · 步步走
typeR · 2023-10-11 · via 步步走

当我们需要从 github 下载项目的时候,它提供了 2 种下载链接:

1
2
https://github.com/ant-design/ant-design.git
git@github.com:ant-design/ant-design.git

上面 2 种下载链接分别使用了 HTTPS 和 SSH 协议。那么这两种协议有什么区别呢?

  • 访问控制:SSH 协议使用公钥和私钥来进行身份验证,因此你需要在远程主机上安装你的公钥。只有拥有私钥的用户才能进行身份验证和访问。相反,HTTPS 协议使用用户名和密码进行身份验证。git clone 或 git fetch 的时候,如果使用 HTTPS 链接则不需要进行身份验证,而 SSH 链接需要。
  • 传输速度:SSH 协议在传输数据时进行压缩,因此它可以在传输大量数据时比 HTTPS 更快。此外,SSH 协议通常可以在传输数据时使用更少的带宽,这对于连接速度较慢的网络非常有用。
  • 防火墙限制: 某些公司或组织可能会在防火墙中阻止对 SSH 端口的访问,这可能会使 SSH 协议无法使用。另一方面,HTTPS 协议通常可以通过防火墙,因为它使用标准的 Web 端口 80 和 443。

想要通过 SSH 链接来下载项目,需要在客户端和服务器之间配置 SSH key,那么如何做呢?下面以 github 为例来说明具体步骤。

1. 在本地生成 SSH key

1
ssh-keygen -t ed25519 -C "user@example.com"

这里我把 user@example.com 替换成了我的 github.com 的邮箱。执行完后可能会有如下提示,不用管直接按回车即可。

1
2
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/johndoe/.ssh/id_ed25519):
1
2
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

最后你会发现会打印这么一串信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
SHA256:ToTEp33dDV8Sokslnx568DC5ABPQTmvlBjGx+r/W0k8 user@example.com
The key's randomart image is:
+--[ED25519 256]--+
|o.+o .. |
|. +o....+ |
| +.= .o. |
|o.+ o . . . |
|o+ . . .So . |
|*. oo+ o . |
|o*. o =E= o |
|ooo.o =..o o |
|.o+o++ .. |
+----[SHA256]-----+

然后你就会发现在 .ssh 目录下多了 2 个文件:

1
2
$ ls ~/.ssh
id_ed25519 id_ed25519.pub

2. 为你的 github 账户添加一个公共的 key

上面已经在本地生成好了 SSH key,现在就要把这个 key 的内容贴到 github 账户里。

执行如下命令后,会在终端打印 key 的内容,可以选中它们然后复制。

1
cat ~/.ssh/id_ed25519.pub

然后按照如下顺序把 key 的内容贴到 github 的账户里。

    1. Log in to your GitHub account.
    1. Navigate to “Settings”.
    1. Click on “SSH and GPG keys” in the left menu.
    1. Click on the “New SSH key” button.

3. 测试是否可用

接下来就可以找个 github 仓库,复制 SSH 的地址进行 clone 了:

1
git clone git@github.com:ant-design/ant-design.git --depth=1

4. 为 SSH 代理指定 SSH key

如果您不想每次 git 使用 SSH 键时输入密码,则可以将键添加到 SSH 代理管理的键列表中。

1
eval "$(ssh-agent -s)"

然后:

1
ssh-add ~/.ssh/id_ed25519

但是每次电脑重启后,如上设置就会失效,需要重新设置。