我可以使用主机名未知的ssh配置文件吗


1

我正在使用一些没有Elatic IP的AWS EC2实例。因此,他们的公共IP地址经常更改。

我是否仍可以使用ssh配置文件来设置连接的所有其他选项,然后在命令行上指定ip地址。还是我每次都要编辑配置文件并更新IP地址?

例如

Host example
    User theboss
    IdentityFile ~/.ssh/example

然后用这个来连接

ssh example -? 123.123.123.123

Answers:


0

您可以在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地址发生变化,该设置也应保持稳定。


主机都使用不同的密钥和用户,因此我将无法以这种方式进行配置。感谢您的回复。
mike

如果您使用不同的键和用户,则只需为每个键和条目创建一个条目。您可以在其节中更改主机的目标。参见编辑。
BillThor
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.