Interactive ssh connection does not work












0















For some reason I have a master script that required below coding:



vi test_run.sh    
#!/bin/sh
ssh -tt 192.168.1.20


To execute the command I run:



cat test_run.sh | sh -


I'm able to connect to the remote server but I can't issue any command there, e.g ls follow by Enter, cause the screen to hang.










share|improve this question

























  • Why are you doing cat foo | sh - instead of just foo?

    – Sparhawk
    4 hours ago






  • 1





    @Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

    – Kusalananda
    1 hour ago













  • does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

    – dominix
    52 mins ago
















0















For some reason I have a master script that required below coding:



vi test_run.sh    
#!/bin/sh
ssh -tt 192.168.1.20


To execute the command I run:



cat test_run.sh | sh -


I'm able to connect to the remote server but I can't issue any command there, e.g ls follow by Enter, cause the screen to hang.










share|improve this question

























  • Why are you doing cat foo | sh - instead of just foo?

    – Sparhawk
    4 hours ago






  • 1





    @Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

    – Kusalananda
    1 hour ago













  • does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

    – dominix
    52 mins ago














0












0








0








For some reason I have a master script that required below coding:



vi test_run.sh    
#!/bin/sh
ssh -tt 192.168.1.20


To execute the command I run:



cat test_run.sh | sh -


I'm able to connect to the remote server but I can't issue any command there, e.g ls follow by Enter, cause the screen to hang.










share|improve this question
















For some reason I have a master script that required below coding:



vi test_run.sh    
#!/bin/sh
ssh -tt 192.168.1.20


To execute the command I run:



cat test_run.sh | sh -


I'm able to connect to the remote server but I can't issue any command there, e.g ls follow by Enter, cause the screen to hang.







ssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 mins ago









Kusalananda

126k16239393




126k16239393










asked 4 hours ago









user324294user324294

113




113













  • Why are you doing cat foo | sh - instead of just foo?

    – Sparhawk
    4 hours ago






  • 1





    @Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

    – Kusalananda
    1 hour ago













  • does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

    – dominix
    52 mins ago



















  • Why are you doing cat foo | sh - instead of just foo?

    – Sparhawk
    4 hours ago






  • 1





    @Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

    – Kusalananda
    1 hour ago













  • does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

    – dominix
    52 mins ago

















Why are you doing cat foo | sh - instead of just foo?

– Sparhawk
4 hours ago





Why are you doing cat foo | sh - instead of just foo?

– Sparhawk
4 hours ago




1




1





@Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

– Kusalananda
1 hour ago







@Sparhawk Probably because they haven't chmod +x test_run.sh. Still, sh test_run.sh would have been better than the cat through a pipe.

– Kusalananda
1 hour ago















does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

– dominix
52 mins ago





does it return something if you type ssh 192.168.1.20 'echo yes' ? if no i might be an ssh problem, if yes if might then be an MTU problem between your machine and 192.168.1.20.

– dominix
52 mins ago










1 Answer
1






active

oldest

votes


















2














ssh will inherit the standard input stream of the shell that executes it.



The standard input of the shell that executes ssh is being used to read the shell script (from the pipe from cat), and is therefore not available for interactively issuing commands to ssh. This is why you are trying with -tt to make the ssh session interactive (ssh would complain otherwise, saying Pseudo-terminal will not be allocated because stdin is not a terminal), but it doesn't work because, as mentioned, the stream that is used supply it with commands from the user is being used by the shell to read the actual script.



Instead, run the script as usual:



sh test_run.sh


This would leave the standard input stream available for you to issue commands interactively to the remote shell session, and your invocation of ssh would also not need -tt at all.



If your script was a bit longer:



#!/bin/sh

ssh -tt 192.168.1.20
hostname
echo "DONE"


and if you ran it as



cat test_run.sh | sh -


you would notice that the machine that executes both hostname and the echo is actually the remote machine. This is because the standard input of the shell (connected to the stream read from cat, containing the script) will be passed on to ssh. This has the effect of passing the commands in the script on to the shell started on the remote system (as if you typed them into the remote shell).






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f496594%2finteractive-ssh-connection-does-not-work%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    ssh will inherit the standard input stream of the shell that executes it.



    The standard input of the shell that executes ssh is being used to read the shell script (from the pipe from cat), and is therefore not available for interactively issuing commands to ssh. This is why you are trying with -tt to make the ssh session interactive (ssh would complain otherwise, saying Pseudo-terminal will not be allocated because stdin is not a terminal), but it doesn't work because, as mentioned, the stream that is used supply it with commands from the user is being used by the shell to read the actual script.



    Instead, run the script as usual:



    sh test_run.sh


    This would leave the standard input stream available for you to issue commands interactively to the remote shell session, and your invocation of ssh would also not need -tt at all.



    If your script was a bit longer:



    #!/bin/sh

    ssh -tt 192.168.1.20
    hostname
    echo "DONE"


    and if you ran it as



    cat test_run.sh | sh -


    you would notice that the machine that executes both hostname and the echo is actually the remote machine. This is because the standard input of the shell (connected to the stream read from cat, containing the script) will be passed on to ssh. This has the effect of passing the commands in the script on to the shell started on the remote system (as if you typed them into the remote shell).






    share|improve this answer






























      2














      ssh will inherit the standard input stream of the shell that executes it.



      The standard input of the shell that executes ssh is being used to read the shell script (from the pipe from cat), and is therefore not available for interactively issuing commands to ssh. This is why you are trying with -tt to make the ssh session interactive (ssh would complain otherwise, saying Pseudo-terminal will not be allocated because stdin is not a terminal), but it doesn't work because, as mentioned, the stream that is used supply it with commands from the user is being used by the shell to read the actual script.



      Instead, run the script as usual:



      sh test_run.sh


      This would leave the standard input stream available for you to issue commands interactively to the remote shell session, and your invocation of ssh would also not need -tt at all.



      If your script was a bit longer:



      #!/bin/sh

      ssh -tt 192.168.1.20
      hostname
      echo "DONE"


      and if you ran it as



      cat test_run.sh | sh -


      you would notice that the machine that executes both hostname and the echo is actually the remote machine. This is because the standard input of the shell (connected to the stream read from cat, containing the script) will be passed on to ssh. This has the effect of passing the commands in the script on to the shell started on the remote system (as if you typed them into the remote shell).






      share|improve this answer




























        2












        2








        2







        ssh will inherit the standard input stream of the shell that executes it.



        The standard input of the shell that executes ssh is being used to read the shell script (from the pipe from cat), and is therefore not available for interactively issuing commands to ssh. This is why you are trying with -tt to make the ssh session interactive (ssh would complain otherwise, saying Pseudo-terminal will not be allocated because stdin is not a terminal), but it doesn't work because, as mentioned, the stream that is used supply it with commands from the user is being used by the shell to read the actual script.



        Instead, run the script as usual:



        sh test_run.sh


        This would leave the standard input stream available for you to issue commands interactively to the remote shell session, and your invocation of ssh would also not need -tt at all.



        If your script was a bit longer:



        #!/bin/sh

        ssh -tt 192.168.1.20
        hostname
        echo "DONE"


        and if you ran it as



        cat test_run.sh | sh -


        you would notice that the machine that executes both hostname and the echo is actually the remote machine. This is because the standard input of the shell (connected to the stream read from cat, containing the script) will be passed on to ssh. This has the effect of passing the commands in the script on to the shell started on the remote system (as if you typed them into the remote shell).






        share|improve this answer















        ssh will inherit the standard input stream of the shell that executes it.



        The standard input of the shell that executes ssh is being used to read the shell script (from the pipe from cat), and is therefore not available for interactively issuing commands to ssh. This is why you are trying with -tt to make the ssh session interactive (ssh would complain otherwise, saying Pseudo-terminal will not be allocated because stdin is not a terminal), but it doesn't work because, as mentioned, the stream that is used supply it with commands from the user is being used by the shell to read the actual script.



        Instead, run the script as usual:



        sh test_run.sh


        This would leave the standard input stream available for you to issue commands interactively to the remote shell session, and your invocation of ssh would also not need -tt at all.



        If your script was a bit longer:



        #!/bin/sh

        ssh -tt 192.168.1.20
        hostname
        echo "DONE"


        and if you ran it as



        cat test_run.sh | sh -


        you would notice that the machine that executes both hostname and the echo is actually the remote machine. This is because the standard input of the shell (connected to the stream read from cat, containing the script) will be passed on to ssh. This has the effect of passing the commands in the script on to the shell started on the remote system (as if you typed them into the remote shell).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 mins ago

























        answered 18 mins ago









        KusalanandaKusalananda

        126k16239393




        126k16239393






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496594%2finteractive-ssh-connection-does-not-work%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            CARDNET

            Boot-repair Failure: Unable to locate package grub-common:i386

            濃尾地震