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

Commit 14fae54

Browse files
committed
ssh_config
1 parent c7511f1 commit 14fae54

7 files changed

Lines changed: 111 additions & 0 deletions

File tree

docs/.vitepress/config/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function sidebarGuide(): DefaultTheme.Sidebar {
6464
text: '附录',
6565
items: [
6666
{ text: '提问的艺术', link: '/appendix/how-to-ask' },
67+
{ text: 'SSH 配置指南', link: '/appendix/ssh配置指南' },
6768
]
6869
},
6970
{

docs/appendix/remote_explorer.png

43.2 KB
Loading

docs/appendix/ssh_config.png

86.5 KB
Loading

docs/appendix/ssh_config2.png

106 KB
Loading

docs/appendix/ssh_server.png

55.6 KB
Loading

docs/appendix/ssh_server2.png

103 KB
Loading

docs/appendix/ssh配置指南.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
### 检查现有密钥
22+
23+
在生成新密钥之前,先检查是否已经存在 SSH 密钥:
24+
25+
```bash
26+
# 在终端输入以下命令
27+
ls -la ~/.ssh
28+
```
29+
30+
如果目录不存在或为空,说明您还没有 SSH 密钥,可以继续下面的步骤。
31+
32+
> [!tip]
33+
>
34+
>如果您有 `id_rsa``id_rsa.pub` 文件,说明您已经有 SSH 密钥对了。可以移步到配置服务器连接。
35+
36+
### 生成新的密钥对
37+
38+
在终端中输入以下命令生成 SSH 密钥对:
39+
40+
```bash
41+
# 在终端输入,替换自己的邮箱地址
42+
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
43+
```
44+
45+
执行上述命令后,系统会提示您进行一系列配置:
46+
47+
```bash
48+
# 连按三个回车即可
49+
Enter file in which to save the key (/Users/yourusername/.ssh/id_rsa):
50+
Enter passphrase (empty for no passphrase):
51+
Enter same passphrase again:
52+
```
53+
54+
### 验证密钥生成
55+
56+
密钥生成完成后,您可以查看生成的文件:
57+
58+
```bash
59+
ls -la ~/.ssh
60+
```
61+
62+
您应该能看到以下文件:
63+
64+
- `id_rsa`:私钥文件(请妥善保管,不要泄露)
65+
- `id_rsa.pub`:公钥文件(可以安全地分享给服务器)
66+
67+
查看公钥内容:
68+
69+
```bash
70+
cat ~/.ssh/id_rsa.pub
71+
```
72+
73+
观察到输出为:`ssh-rsa xxxxxxxxxxxxxxx = xxxxx@xxxx.xx` 即正确
74+
75+
## 3. 将服务器与 VS Code 连接
76+
77+
### 在 VS Code 中,安装对应拓展
78+
79+
![remote_explorer](remote_explorer.png)
80+
81+
### 配置文件
82+
83+
- 在左侧找到形如电脑的图标
84+
- 点击SSH旁边的齿轮
85+
- 进入默认配置文件
86+
87+
![ssh_config](ssh_config2.png)
88+
89+
### 连接服务器
90+
91+
- 点击SSH旁边的加号,新建远程
92+
- 在图中所示方框中输入以下命令连接到服务器:
93+
94+
```bash
95+
ssh root@服务器地址 -p 端口号
96+
```
97+
98+
![ssh_server](ssh_server2.png)
99+
100+
首次连接时,系统会显示服务器的指纹信息并询问是否信任:
101+
102+
```bash
103+
The authenticity of host 'xxxxxxx' can't be established.
104+
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
105+
Are you sure you want to continue connecting (yes/no/[fingerprint])?
106+
```
107+
108+
输入 `yes` 并按回车键继续。
109+
110+
如果配置正确,您应该能够成功登录到服务器而无需输入密码。

0 commit comments

Comments
 (0)