如何在 ssh 設定檔中撤銷特定主機上的全域 RemoteCommand 配置

如何在 ssh 設定檔中撤銷特定主機上的全域 RemoteCommand 配置

我有以下~/.ssh/config文件:

Host myserver1
    Hostname myserver1.blop.com
    User blup

Host myserver2
    Hostname myserver2.blop.com
    User blup

Host bitbucket.org
    RemoteCommand # Want to not take care of global RemoteCommand
    RequestTTY no

Host *
    User root
    RemoteCommand PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' $SHELL;
    RequestTTY yes

我希望RemoteCommand在登入後在遠端 shell 上更改 PROMPT_COMMAND 的所有伺服器上都有一個預設值。 (這是有效的)該RemoteCommand選項使與 bitbucket (git) 的連接失敗,並且我沒有找到禁用RemoteCommand特定主機的方法。

嘗試過:什麼都沒有,空字串""$SHELL;

任何想法 ?有RemoteCommand恢復預設值嗎?

答案1

  1. 用作noneRemoteCommand
Host bitbucket.org
    RemoteCommand none
    RequestTTY no
  1. 一個替代方法就是簡單地將 bitbucket.org 從預設主機配置中排除:
Host * !bitbucket.org
    User root
    RemoteCommand PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' $SHELL;
    RequestTTY yes
  1. 更好的解決方案,對於我的具體問題RemoteCommand,添加 aMatch以僅應用ssh命令的設定:

只需將其添加到文件頂部即可

Match exec "test $_ = /usr/bin/ssh"
    RemoteCommand PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' $SHELL;
    RequestTTY yes

相關內容