我有一个命令,看起来像这样:
$ ssh [long list of parameters, eventually I connect to internalhost]
Run Code Online (Sandbox Code Playgroud)
我的任务是用 just 替换这个长长的参数列表internalhost
,这样我就可以像这样运行它
$ ssh internalhost
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
bas*_*lab 10
标准 SSH 客户端在任何连接之前读取配置文件:
/etc/ssh/ssh_config # system-wide
~/.ssh/config # per user
Run Code Online (Sandbox Code Playgroud)
后者具有更高的优先级。
理想情况下,您希望使用适合所有用户的参数配置系统范围的配置,并使用特定于您的选项来配置您的 homedir 中的配置。
这是一个例子~/.ssh/config
Host remote.example.com
User dev1
IdentityFIle ~/.ssh/id_rsa_remote
Run Code Online (Sandbox Code Playgroud)
然后连接:
ssh remote.example.com
Run Code Online (Sandbox Code Playgroud)
注意:
~/.ssh/config
必须对用户具有读/写权限,并且其他人不能访问 (chmod 600 ~/.ssh/config
)
所有可能的选项都记录在 ssh_config 手册页中:man ssh_config
我通常使用.ssh/config
在我的主目录中找到的文件来运行我的 OpenSSH 客户端,格式为ssh ubserver
. 在此处找到的该文件中,/home/$USER/.ssh
我具有以下配置:
Host ubserver
Hostname 127.0.0.1
Port 2222
User george
Run Code Online (Sandbox Code Playgroud)
意思是我可以简单地做:
ssh ubserver
Run Code Online (Sandbox Code Playgroud)
并连接到所述服务器,而无需在终端中输入多于该行的内容。