ssh的config文件学习
目录
注意
本文最后更新于 2024-12-04,文中内容可能已过时。
以下内容来自 https://zhuanlan.zhihu.com/p/716963359
- 基本配置
Host Server1
Hostname 172.16.0.1
User zhangsan
Port 22
ServerAliveInterval 180
IdentityFile ~/.ssh/secret_key.pem
- 通配符。可以使用通配符来将公共的配置写在一起。
Host Server*
User zhangsan
Port 22
ServerAliveInterval 180
Host Server1
Hostname 172.16.0.1
Host Server2
Hostname 172.16.0.2
Host Server3
Hostname 172.16.0.3
- 多文件管理。可以引用其他文件中的内容。也可以使用通配符表示一系列文件。
Include config-cluster-shanghai
Include config-*
- 使用ProxyJump来配置跳板机。连接所有以
Server
开头的服务器都会通过Jumper
这个配置进行跳板。
Host Jumper
Hostname 1.2.3.4
User zhangsan
Host Server*
User zhangsan
ProxyJump Jumper
ServerAliveInterval 180
Host Server1
Hostname 172.16.0.1
Host Server2
Hostname 172.16.0.2
- 使用scp可以直接在Server1和Server2之间传输文件。如果两者不能直接访问,可以添加
-3
增加本地机器作为中转。
scp Server1:/path/to/file Server2:/path/to/file2
scp -3 Server1:/path/to/file Server2:/path/to/file2