Is it possible to have conditional options in ~/.ssh/config based on the calling application (ssh or sshfs)?

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











up vote
1
down vote

favorite
1












In my ~/.ssh/config file I have the following option:



RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'



This automatically starts tmux and connects to an existing session if possible when connecting via ssh.



This causes sshfs to fail to connect with the error read: Connection reset by peer.



Is there a way to apply this options selectively only when connecting with ssh and not when attempting to mount a filesystem with sshfs?



Note that I still want to load the remainder of the options in that file for sshfs, since they are still relevant. Using sshfs -F /dev/null is not an option.



I could of course create two separate configuration files for ssh and sshfs, but that would require a bunch of duplication that seems unecessary.










share|improve this question





















  • In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
    – andcoz
    Sep 5 at 13:35










  • @andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
    – maxf130
    Sep 5 at 14:56















up vote
1
down vote

favorite
1












In my ~/.ssh/config file I have the following option:



RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'



This automatically starts tmux and connects to an existing session if possible when connecting via ssh.



This causes sshfs to fail to connect with the error read: Connection reset by peer.



Is there a way to apply this options selectively only when connecting with ssh and not when attempting to mount a filesystem with sshfs?



Note that I still want to load the remainder of the options in that file for sshfs, since they are still relevant. Using sshfs -F /dev/null is not an option.



I could of course create two separate configuration files for ssh and sshfs, but that would require a bunch of duplication that seems unecessary.










share|improve this question





















  • In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
    – andcoz
    Sep 5 at 13:35










  • @andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
    – maxf130
    Sep 5 at 14:56













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





In my ~/.ssh/config file I have the following option:



RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'



This automatically starts tmux and connects to an existing session if possible when connecting via ssh.



This causes sshfs to fail to connect with the error read: Connection reset by peer.



Is there a way to apply this options selectively only when connecting with ssh and not when attempting to mount a filesystem with sshfs?



Note that I still want to load the remainder of the options in that file for sshfs, since they are still relevant. Using sshfs -F /dev/null is not an option.



I could of course create two separate configuration files for ssh and sshfs, but that would require a bunch of duplication that seems unecessary.










share|improve this question













In my ~/.ssh/config file I have the following option:



RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'



This automatically starts tmux and connects to an existing session if possible when connecting via ssh.



This causes sshfs to fail to connect with the error read: Connection reset by peer.



Is there a way to apply this options selectively only when connecting with ssh and not when attempting to mount a filesystem with sshfs?



Note that I still want to load the remainder of the options in that file for sshfs, since they are still relevant. Using sshfs -F /dev/null is not an option.



I could of course create two separate configuration files for ssh and sshfs, but that would require a bunch of duplication that seems unecessary.







ssh sshfs ssh-config






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 5 at 9:09









maxf130

1083




1083











  • In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
    – andcoz
    Sep 5 at 13:35










  • @andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
    – maxf130
    Sep 5 at 14:56

















  • In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
    – andcoz
    Sep 5 at 13:35










  • @andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
    – maxf130
    Sep 5 at 14:56
















In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
– andcoz
Sep 5 at 13:35




In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question.
– andcoz
Sep 5 at 13:35












@andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
– maxf130
Sep 5 at 14:56





@andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-)
– maxf130
Sep 5 at 14:56











1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Suppose you used a different hostname when you want to use tmux eg



for sshfs :



ssh user@remotehost


but for tmux



ssh user@remotehost_tmux


and then in your ~/.ssh/config have a section specific for the host remotehost_tmux



eg.



# Global Options
#UseRoaming no

# Hostname specific options
Host <hostname>_tmux
RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
Hostname <hostname>
#





share|improve this answer






















    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%2f466968%2fis-it-possible-to-have-conditional-options-in-ssh-config-based-on-the-calling%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










    Suppose you used a different hostname when you want to use tmux eg



    for sshfs :



    ssh user@remotehost


    but for tmux



    ssh user@remotehost_tmux


    and then in your ~/.ssh/config have a section specific for the host remotehost_tmux



    eg.



    # Global Options
    #UseRoaming no

    # Hostname specific options
    Host <hostname>_tmux
    RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
    Hostname <hostname>
    #





    share|improve this answer


























      up vote
      1
      down vote



      accepted










      Suppose you used a different hostname when you want to use tmux eg



      for sshfs :



      ssh user@remotehost


      but for tmux



      ssh user@remotehost_tmux


      and then in your ~/.ssh/config have a section specific for the host remotehost_tmux



      eg.



      # Global Options
      #UseRoaming no

      # Hostname specific options
      Host <hostname>_tmux
      RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
      Hostname <hostname>
      #





      share|improve this answer
























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Suppose you used a different hostname when you want to use tmux eg



        for sshfs :



        ssh user@remotehost


        but for tmux



        ssh user@remotehost_tmux


        and then in your ~/.ssh/config have a section specific for the host remotehost_tmux



        eg.



        # Global Options
        #UseRoaming no

        # Hostname specific options
        Host <hostname>_tmux
        RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
        Hostname <hostname>
        #





        share|improve this answer














        Suppose you used a different hostname when you want to use tmux eg



        for sshfs :



        ssh user@remotehost


        but for tmux



        ssh user@remotehost_tmux


        and then in your ~/.ssh/config have a section specific for the host remotehost_tmux



        eg.



        # Global Options
        #UseRoaming no

        # Hostname specific options
        Host <hostname>_tmux
        RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
        Hostname <hostname>
        #






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 5 at 13:03

























        answered Sep 5 at 12:42









        X Tian

        7,34611836




        7,34611836



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466968%2fis-it-possible-to-have-conditional-options-in-ssh-config-based-on-the-calling%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)