Interactive ssh connection does not work

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












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
    Jan 25 at 3:40






  • 2





    @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
    Jan 25 at 6:41












  • 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
    Jan 25 at 6:54















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
    Jan 25 at 3:40






  • 2





    @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
    Jan 25 at 6:41












  • 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
    Jan 25 at 6:54













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 Jan 25 at 7:41









Kusalananda

129k16245404




129k16245404










asked Jan 25 at 2:52









user324294user324294

113




113












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

    – Sparhawk
    Jan 25 at 3:40






  • 2





    @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
    Jan 25 at 6:41












  • 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
    Jan 25 at 6:54

















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

    – Sparhawk
    Jan 25 at 3:40






  • 2





    @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
    Jan 25 at 6:41












  • 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
    Jan 25 at 6:54
















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

– Sparhawk
Jan 25 at 3:40





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

– Sparhawk
Jan 25 at 3:40




2




2





@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
Jan 25 at 6:41






@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
Jan 25 at 6:41














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
Jan 25 at 6:54





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
Jan 25 at 6:54










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 Jan 25 at 7:42

























        answered Jan 25 at 7:29









        KusalanandaKusalananda

        129k16245404




        129k16245404



























            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

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay