目录

ssh的config文件学习

目录
注意
本文最后更新于 2024-12-04,文中内容可能已过时。

以下内容来自 https://zhuanlan.zhihu.com/p/716963359

  1. 基本配置

config


Host Server1
    Hostname 172.16.0.1
    User zhangsan
    Port 22
    ServerAliveInterval 180
    IdentityFile ~/.ssh/secret_key.pem
  1. 通配符。可以使用通配符来将公共的配置写在一起。

text

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
  1. 多文件管理。可以引用其他文件中的内容。也可以使用通配符表示一系列文件。

text

Include config-cluster-shanghai
Include config-*
  1. 使用ProxyJump来配置跳板机。连接所有以Server开头的服务器都会通过Jumper这个配置进行跳板。

text

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   
  1. 使用scp可以直接在Server1和Server2之间传输文件。如果两者不能直接访问,可以添加-3增加本地机器作为中转。

text

   scp Server1:/path/to/file Server2:/path/to/file2
   scp -3 Server1:/path/to/file Server2:/path/to/file2