Alias a command that is behind SSH jumpbox

dor*_*emi 2 ssh alias

In order to run a script, I currently have to do a two step process:

ssh remote_machine
./run_script
Run Code Online (Sandbox Code Playgroud)

Is it possible to setup an alias on my host machine such that I can execute an alias, for example: run_script and it will automatically log me into the remote_machine and run the script?

jay*_*ren 5

Sure, I do this all the time:

alias run_script="ssh remote_machine ./run_script"
Run Code Online (Sandbox Code Playgroud)

Note that if the ./run_script script is interactive, you'll need to allocate a TTY using the -t flag to ssh:

alias run_script="ssh -t remote_machine ./run_script"
Run Code Online (Sandbox Code Playgroud)

  • 另请注意,如果 `run_script` 不在正在登录的用户的主目录中,您可能希望(取决于脚本)将 `cd` 放入该目录和/或指定脚本的完整路径,例如 ` ssh user@remote 'cd /path/to/tools; ./run_script'` 或 `ssh user@remove /path/to/run_script` 分别。 (2认同)