得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

探 ssh_config

SSH Client 的参数值来源主要有 3 个,分别是命令行选项~/.ssh/config/etc/ssh/ssh_config

最近用上了 vscode 的 ssh remote 插件,不得不用上 ssh_config 文件,所以初步了解一下 ~/.ssh/config、/etc/ssh/ssh_config

先说说 SSH Client 的参数值的来源优先级,以此为

  1. 命令行选项
  2. 用户配置文件 (~/.ssh/config)
  3. 系统级配置文件 (/etc/ssh/ssh_config)

简单了解 ssh_config 中常见的一些配置和配置规则,更多配置项请参考官方文档或者执行 ssh_config 命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 常见的配置字段
# Host 别名,可以使用通配符(* 表示任意字符串,? 表示任意单个字符)
# HostName 主机名,支持完整域名,缩写别名,IP 地址,也支持转义序列 %h,该转义序列指代命令行中输入的 host name
# Port 指定 SSH Server 监听的端口
# User 建立 SSH 连接使用的用户名
# IdentityFile 建立 SSH 连接使用的私钥文件的路径

# example
Host test
HostName www.test.com.cn
User test
Port 22
Host *
User test2
IdentityFile ~/.ssh/id_ed25519

由于存在通配符,一个别名可能匹配到多个 Host 段,ssh 命令会按照配置小节的配置顺序,依次进行命中测试,首次命中不停止,直到找出所有命中配置小节,并且使用先获得的配置参数,即,在配置文件中越靠前的配置会被使用

1
2
3
4
5
6
$ ssh test  # host name 为 test
# 命中第一个 Host 也命中第二个 Host,最终生效的配置如下
# HostName www.test.com.cn
# User test
# Port 22
# IdentityFile ~/.ssh/id_ed25519

be slow to promise and quick to perform.