假设我想ssh在我的.ssh config文件中使用相同的设置为 30 个服务器配置我的选项:
host XXX
HostName XXX.YYY.com
User my_username
Compression yes
Ciphers arcfour,blowfish-cbc
Protocol 2
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
IdentityFile ~/.ssh/YYY/id_rsa
Run Code Online (Sandbox Code Playgroud)
这 30 台机器之间唯一变化的地方是XXX.
除了在我的config文件中重复上述结构 30 次之外,还有另一种方法来定义一系列机器吗?
Ign*_*ams 294
从ssh_config(5)手册页:
Run Code Online (Sandbox Code Playgroud)Host Restricts the following declarations (up to the next Host key? word) to be only for those hosts that match one of the patterns given after the keyword. If more than one pattern is provided, they should be separated by whitespace....
Run Code Online (Sandbox Code Playgroud)HostName Specifies the real host name to log into. This can be used to specify nicknames or abbreviations for hosts. If the hostname contains the character sequence ‘%h’, then this will be replaced with the host name specified on the commandline (this is useful for manipulating unqualified names).
所以:
Host XXX1 XXX2 XXX3
HostName %h.YYY.com
Run Code Online (Sandbox Code Playgroud)
Gui*_*ent 130
为了最小化设置,你可以有一个.ssh/config这样的
Host X01
HostName X01.YYY.com
Host X02
HostName X02.YYY.com
...
Host X01 X02 ...
User my_username
Compression yes
Ciphers arcfour,blowfish-cbc
Protocol 2
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
IdentityFile ~/.ssh/YYY/id_rsa
Run Code Online (Sandbox Code Playgroud)
Host X01 X02 ...Host *如果每个主机都具有以下配置,则可以替换为
H.-*_*itt 63
只需使用 *
见man ssh_config:
模式 模式由零个或多个非空白字符、“*”(匹配零个或多个字符的通配符)或“?”组成。(恰好匹配一个字符的通配符)。例如,要为“.co.uk”域集中的任何主机指定一组声明,可以使用以下模式:
Host *.co.uk
The following pattern would match any host in the 192.168.0.[0-9] network range:
Host 192.168.0.?
A pattern-list is a comma-separated list of patterns. Patterns within pattern-lists may be negated by preceding them with an
exclamation mark (‘!’). For example, to allow a key to be used from anywhere within an organisation except from the “dialup”
pool, the following entry (in authorized_keys) could be used:
from="!*.dialup.example.com,*.example.com"
Run Code Online (Sandbox Code Playgroud)
小智 14
从 Ignacio Vazquez-Abrams 和 H.-Dirk Schmitt 的回答中,可以将以下内容添加到 .ssh/config
HOST XXX*
HostName %h.YYY.com
User myname
Run Code Online (Sandbox Code Playgroud)
然后,例如,您可以通过以下方式以 myname@XXX2.YYY.com 登录
ssh XXX2
Run Code Online (Sandbox Code Playgroud)
小智 9
这对我有用:
规范化主机名 是 规范域 xxx.auckland.ac.nz yyy.auckland.ac.nz 主机 *.xxx.auckland.ac.nz 用户 myuser 主机 *.yyy.auckland.ac.nz 用户 myuser
这允许人们使用域内的名称并更改用户名:
蓝瓶:~ user_one$ ssh itslogprd05 myuser@itslogprd05.xxx.auckland.ac.nz 的密码:
| 归档时间: |
|
| 查看次数: |
137596 次 |
| 最近记录: |