How to configure SSH with a RemoteCommand only for interactive sessions (i.e. without command, or not sftp)

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Currently I use Fish as my main shell on local and remote hosts.



I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config:



Host example.com
RemoteCommand tmux a; or tmux
RequestTTY yes


The problem is that now I cannot connect through sftp, nor can I run a direct command from my local CLI:



➤ ssh example.com ping localhost
Cannot execute command-line and remote command.

➤ sftp example.com
Cannot execute command-line and remote command.
Connection closed


So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?







share|improve this question























    up vote
    1
    down vote

    favorite












    Currently I use Fish as my main shell on local and remote hosts.



    I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config:



    Host example.com
    RemoteCommand tmux a; or tmux
    RequestTTY yes


    The problem is that now I cannot connect through sftp, nor can I run a direct command from my local CLI:



    ➤ ssh example.com ping localhost
    Cannot execute command-line and remote command.

    ➤ sftp example.com
    Cannot execute command-line and remote command.
    Connection closed


    So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Currently I use Fish as my main shell on local and remote hosts.



      I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config:



      Host example.com
      RemoteCommand tmux a; or tmux
      RequestTTY yes


      The problem is that now I cannot connect through sftp, nor can I run a direct command from my local CLI:



      ➤ ssh example.com ping localhost
      Cannot execute command-line and remote command.

      ➤ sftp example.com
      Cannot execute command-line and remote command.
      Connection closed


      So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?







      share|improve this question











      Currently I use Fish as my main shell on local and remote hosts.



      I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config:



      Host example.com
      RemoteCommand tmux a; or tmux
      RequestTTY yes


      The problem is that now I cannot connect through sftp, nor can I run a direct command from my local CLI:



      ➤ ssh example.com ping localhost
      Cannot execute command-line and remote command.

      ➤ sftp example.com
      Cannot execute command-line and remote command.
      Connection closed


      So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 22 at 8:39









      Yajo

      1484




      1484




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Option 1 )



          You can the option Match ( see man ssh_config )



          Match Host example.com exec "test $_ = /usr/bin/ssh"
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          This will only differentiate difference between ssh & sftp



          Option 2



          You create some placeholder config for your diffe command , example :



          Host tmux.example.com
          HostName example.com
          HostKeyAlias example.com
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          And after you can still use example.com for you sftp / ping usage .






          share|improve this answer





















          • 1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
            – Yajo
            Jun 25 at 9:04










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451253%2fhow-to-configure-ssh-with-a-remotecommand-only-for-interactive-sessions-i-e-wi%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Option 1 )



          You can the option Match ( see man ssh_config )



          Match Host example.com exec "test $_ = /usr/bin/ssh"
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          This will only differentiate difference between ssh & sftp



          Option 2



          You create some placeholder config for your diffe command , example :



          Host tmux.example.com
          HostName example.com
          HostKeyAlias example.com
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          And after you can still use example.com for you sftp / ping usage .






          share|improve this answer





















          • 1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
            – Yajo
            Jun 25 at 9:04














          up vote
          1
          down vote



          accepted










          Option 1 )



          You can the option Match ( see man ssh_config )



          Match Host example.com exec "test $_ = /usr/bin/ssh"
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          This will only differentiate difference between ssh & sftp



          Option 2



          You create some placeholder config for your diffe command , example :



          Host tmux.example.com
          HostName example.com
          HostKeyAlias example.com
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          And after you can still use example.com for you sftp / ping usage .






          share|improve this answer





















          • 1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
            – Yajo
            Jun 25 at 9:04












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Option 1 )



          You can the option Match ( see man ssh_config )



          Match Host example.com exec "test $_ = /usr/bin/ssh"
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          This will only differentiate difference between ssh & sftp



          Option 2



          You create some placeholder config for your diffe command , example :



          Host tmux.example.com
          HostName example.com
          HostKeyAlias example.com
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          And after you can still use example.com for you sftp / ping usage .






          share|improve this answer













          Option 1 )



          You can the option Match ( see man ssh_config )



          Match Host example.com exec "test $_ = /usr/bin/ssh"
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          This will only differentiate difference between ssh & sftp



          Option 2



          You create some placeholder config for your diffe command , example :



          Host tmux.example.com
          HostName example.com
          HostKeyAlias example.com
          RemoteCommand tmux a; or tmux
          RequestTTY yes


          And after you can still use example.com for you sftp / ping usage .







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 24 at 4:14









          EchoMike444

          3942




          3942











          • 1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
            – Yajo
            Jun 25 at 9:04
















          • 1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
            – Yajo
            Jun 25 at 9:04















          1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
          – Yajo
          Jun 25 at 9:04




          1st option didn't work. It seems Fish doesn't export $_. However, I can manually export a variable with set -x auto_tmux 1 and change the match test to "[ 1 -eq $auto_tmux ]"
          – Yajo
          Jun 25 at 9:04












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451253%2fhow-to-configure-ssh-with-a-remotecommand-only-for-interactive-sessions-i-e-wi%23new-answer', 'question_page');

          );

          Post as a guest













































































          AAtsQfaWeG o3VglyU jwdH1H,UI,S2Hp7VsqBSldn,k5R01ZjrXuHJAGq zk6dazxALMu
          GaA VvYnPDUaT6i6FhpMh xF7j8vLnzYxaLmYx1S aCpVh GeLEaADn LEtAjJL 09qpsN92IP5I

          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          How many registers does an x86_64 CPU actually have?

          Displaying single band from multi-band raster using QGIS