
我正在使用一些没有弹性 IP 的 AWS EC2 实例。因此它们的公共 IP 地址经常更改。
我是否仍可以使用 ssh 配置文件来设置连接的所有其他选项,然后在命令行上指定 ip 地址。还是每次我都必须编辑配置文件并更新 ip 地址?
例如
Host example
User theboss
IdentityFile ~/.ssh/example
然后使用它来连接
ssh example -? 123.123.123.123
答案1
您可以配置组下的选项Host *
。
Host *
user theboss
IdentityFile ~/.ssh/example
Host gandalf
Hostname shire.example.com
User bilbo
IdentityFile ~/.ssh/baggins
您可能有一个包含所有选项的示例/etc/ssh/ssh_config
。
Private DNS
在配置中使用实例的名称。即使 IP 地址发生变化,该名称也应该是稳定的。