Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 2aeef86

Browse files
authored
Merge branch 'main' into watt_toolkit
2 parents d37b16d + 7561949 commit 2aeef86

4 files changed

Lines changed: 126 additions & 115 deletions

File tree

docs/.vitepress/config/zh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function sidebarGuide(): DefaultTheme.Sidebar {
6464
text: '附录',
6565
items: [
6666
{ text: '提问的艺术', link: '/appendix/how-to-ask' },
67-
{ text: 'SSH 配置指南', link: '/appendix/ssh配置指南' },
68-
{ text: '使用 Watt Toolkit 代理访问 GitHub', link: '/appendix/watt_toolkit' },
67+
{ text: '使用 SSH 连接服务器', link: '/appendix/ssh-server' },
68+
{ text: '使用 Watt Toolkit 代理访问 GitHub', link: '/appendix/watt_toolkit' }
6969
]
7070
},
7171
{

docs/appendix/ssh-server.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# 使用 SSH 连接服务器
2+
3+
本文档将帮助使用 macOS 系统的同学完成 SSH 密钥对的生成与配置,并连接到本课程提供的服务器环境进行实验。
4+
5+
## 1. SSH 简介
6+
7+
SSH(Secure Shell)是一种加密的网络传输协议,可以在不安全的网络中为网络服务提供安全的传输环境。通过使用 SSH,你可以安全地连接到远程服务器并执行命令。
8+
9+
> [!tip]
10+
>
11+
> **为什么需要 SSH 密钥?**
12+
>
13+
> - **安全性**:相比密码登录,SSH 密钥更加安全
14+
> - **便利性**:配置完成后无需每次输入密码
15+
> - **自动化**:支持脚本自动化操作
16+
17+
如果你好奇密钥是如何工作的,可以参考[这篇文章](https://www.ruanyifeng.com/blog/2011/08/what_is_a_digital_signature.html)
18+
19+
## 2. 生成 SSH 密钥对
20+
21+
下文将引导大家创建自己的 Ed25519 算法加密的 SSH 密钥对。不过,如果你已经有了 RSA 算法加密的密钥对,不用担心,它也能正常工作。
22+
23+
### 检查现有密钥
24+
25+
在生成新密钥之前,先检查是否已经存在 SSH 密钥:
26+
27+
```bash
28+
ls ~/.ssh
29+
```
30+
31+
如果目录不存在或为空,说明你还没有 SSH 密钥,可以继续下面的步骤。
32+
33+
> [!tip]
34+
>
35+
>如果你有 `id_rsa``id_rsa.pub` 文件(由 RSA 算法加密),或 `id_ed25519``id_ed25519.pub` 文件(由 Ed25519 算法加密),说明你已经有 SSH 密钥对了。可以移步到[向他人分享你的公钥](#向他人分享你的公钥)
36+
37+
### 生成新的密钥对
38+
39+
在终端中输入以下命令生成 SSH 密钥对:
40+
41+
```bash
42+
ssh-keygen
43+
```
44+
45+
执行上述命令后,系统会提示你进行一系列配置。除非你有配置 passphrase 的需求并且知道自己在做什么,否则连按三个回车即可。
46+
47+
```bash
48+
Enter file in which to save the key (/home/yourusername/.ssh/id_ed25519):
49+
Enter passphrase (empty for no passphrase):
50+
Enter same passphrase again:
51+
```
52+
53+
### 验证密钥生成
54+
55+
密钥生成完成后,你可以查看生成的文件:
56+
57+
```bash
58+
ls ~/.ssh
59+
```
60+
61+
你应该能看到以下文件:
62+
63+
- `id_ed25519`:私钥文件(请妥善保管,不要泄露)
64+
- `id_ed25519.pub`:公钥文件(可以安全地分享给服务器)
65+
66+
私钥和公钥统称为一组“密钥”或“密钥对”。
67+
68+
### 向他人分享你的公钥
69+
70+
如果你使用 RSA 算法加密的密钥,在终端中运行下面的命令:
71+
72+
```bash
73+
cat ~/.ssh/id_rsa.pub
74+
```
75+
76+
如果你使用 Ed25519 算法加密的密钥,在终端中运行下面的命令:
77+
78+
```bash
79+
cat ~/.ssh/id_ed25519.pub
80+
```
81+
82+
观察到输出为 `ssh-rsa xxxxxxxxxxxxxxx xxxxx@xxxx``ssh-ed25519 xxxxxxxxxxxxxxx xxxxx@xxxx`,这就是你的公钥,可以复制并分享给他人。
83+
84+
## 3. 使用 VS Code 的 Remote 插件进行远程开发
85+
86+
注意,下面的操作请在已经分配到服务器之后再执行。
87+
88+
### 安装 VS Code 插件
89+
90+
![remote_explorer](remote_explorer.png)
91+
92+
### 配置文件
93+
94+
- 在左侧找到形如电脑的图标
95+
- 点击SSH旁边的齿轮
96+
- 进入默认配置文件
97+
98+
![ssh_config](ssh_config2.png)
99+
100+
### 连接服务器
101+
102+
- 点击SSH旁边的加号,新建远程
103+
- 在图中所示方框中输入以下命令连接到服务器:
104+
105+
```bash
106+
ssh root@服务器地址 -p 端口号
107+
```
108+
109+
![ssh_server](ssh_server2.png)
110+
111+
首次连接时,系统会显示服务器的指纹信息并询问是否信任:
112+
113+
```bash
114+
The authenticity of host 'xxxxxxx' can't be established.
115+
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
116+
Are you sure you want to continue connecting (yes/no/[fingerprint])?
117+
```
118+
119+
输入 `yes` 并按回车键继续。
120+
121+
如果配置正确,你应该能够成功登录到服务器而无需输入密码。

docs/appendix/ssh配置指南.md

Lines changed: 0 additions & 110 deletions
This file was deleted.

docs/lab/manual.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ Git 的常用操作可以通过 [Git 学习网站](https://learngitbranching.js.
190190

191191
### SSH
192192

193-
在 ICS 课程中没有直接使用 SSH 连接服务器的内容,但你可能需要[使用 SSH 连接 GitHub](https://docs.github.com/cn/authentication/connecting-to-github-with-ssh/)。SSH 的完整文档可以通过 man ssh 查阅
193+
本课程中,使用 Mac 的同学需要使用 SSH 连接服务器,请参考[这个文档](/appendix/ssh-server)
194194

195-
如果你从未使用过 SSH,你可能需要为自己创建一个密钥对,参考指令:`ssh-keygen -t ed25519 -C "your_email@example.com"`。密钥对的默认保存位置为 `~/.ssh/`,其中的 `id_rsa` 为私钥,`id_rsa.pub` 为公钥。如果你好奇密钥是如何工作的,可以参考[这篇文章](https://www.ruanyifeng.com/blog/2011/08/what_is_a_digital_signature.html)
195+
你可能还需要[使用 SSH 连接 GitHub](https://docs.github.com/cn/authentication/connecting-to-github-with-ssh/)。SSH 的完整文档可以通过 man ssh 查阅
196196

197197
### Vim
198198

199199
Vim 的基本用法为运行 `vim something.txt` 打开文件,然后按 `i` 键编辑文件,此时可以直接打字,完成后按 `ESC` 键,输入 `:wq` 保存并退出,或输入 `:q!` 不保存直接退出。
200200

201201
由于 Vim 有一些学习难度,大家当然可以直接选择开箱即用的 VS Code ,但是如果你习惯了 Vim 的操作,用起来就非常爽快。
202202

203-
Vim 的用法非常丰富,如有兴趣可以通过 Vim 自带的教程程序 `vimtutor` 学习(在安装 vim 之后直接在命令行输入这个即可),也可以通过 [Vim 学习网站](https://vim-adventures.com/)学习,或者参考[这个保姆级入门视频](https://www.bilibili.com/video/BV13t4y1t7Wg)
203+
Vim 的用法非常丰富,如有兴趣可以通过 Vim 自带的教程程序 `vimtutor` 学习(在安装 Vim 之后直接在命令行输入这个即可),也可以通过 [Vim 学习网站](https://vim-adventures.com/)学习,或者参考[这个保姆级入门视频](https://www.bilibili.com/video/BV13t4y1t7Wg)
204204

205205
> Copilot 官方提供了一个 [Vim 插件](https://github.com/github/copilot.vim),可以让你在 Vim 中使用 Copilot。
206206

0 commit comments

Comments
 (0)