Confused between “echo command | ssh server” and “ssh server command”

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
6
down vote

favorite












During the course of my learning about the non-interactive login shell, I have come across 2 ways to remotely execute the commands via SSH. For me, they both look to be the same. But unfortunately, they aren't.



With the command echo "shopt login_shell; echo $-" | ssh -l poweruser 192.168.1.67, I get the following output.



Pseudo-terminal will not be allocated because stdin is not a terminal.
poweruser@192.168.1.67's password:
login_shell on
hBs


But with the command ssh -l poweruser 192.168.1.67 "shopt login_shell; echo $-", I get a different output.



poweruser@192.168.1.67's password:
login_shell off
hBc


Could you please tell why the shell is not a login shell in the second case even though it prompts for the password.







share|improve this question





















  • As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
    – Duncan X Simpson
    Jul 30 at 17:23
















up vote
6
down vote

favorite












During the course of my learning about the non-interactive login shell, I have come across 2 ways to remotely execute the commands via SSH. For me, they both look to be the same. But unfortunately, they aren't.



With the command echo "shopt login_shell; echo $-" | ssh -l poweruser 192.168.1.67, I get the following output.



Pseudo-terminal will not be allocated because stdin is not a terminal.
poweruser@192.168.1.67's password:
login_shell on
hBs


But with the command ssh -l poweruser 192.168.1.67 "shopt login_shell; echo $-", I get a different output.



poweruser@192.168.1.67's password:
login_shell off
hBc


Could you please tell why the shell is not a login shell in the second case even though it prompts for the password.







share|improve this question





















  • As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
    – Duncan X Simpson
    Jul 30 at 17:23












up vote
6
down vote

favorite









up vote
6
down vote

favorite











During the course of my learning about the non-interactive login shell, I have come across 2 ways to remotely execute the commands via SSH. For me, they both look to be the same. But unfortunately, they aren't.



With the command echo "shopt login_shell; echo $-" | ssh -l poweruser 192.168.1.67, I get the following output.



Pseudo-terminal will not be allocated because stdin is not a terminal.
poweruser@192.168.1.67's password:
login_shell on
hBs


But with the command ssh -l poweruser 192.168.1.67 "shopt login_shell; echo $-", I get a different output.



poweruser@192.168.1.67's password:
login_shell off
hBc


Could you please tell why the shell is not a login shell in the second case even though it prompts for the password.







share|improve this question













During the course of my learning about the non-interactive login shell, I have come across 2 ways to remotely execute the commands via SSH. For me, they both look to be the same. But unfortunately, they aren't.



With the command echo "shopt login_shell; echo $-" | ssh -l poweruser 192.168.1.67, I get the following output.



Pseudo-terminal will not be allocated because stdin is not a terminal.
poweruser@192.168.1.67's password:
login_shell on
hBs


But with the command ssh -l poweruser 192.168.1.67 "shopt login_shell; echo $-", I get a different output.



poweruser@192.168.1.67's password:
login_shell off
hBc


Could you please tell why the shell is not a login shell in the second case even though it prompts for the password.









share|improve this question












share|improve this question




share|improve this question








edited Jul 30 at 10:31









JayTheKay

1032




1032









asked Jul 30 at 5:32









Karthik

333




333











  • As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
    – Duncan X Simpson
    Jul 30 at 17:23
















  • As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
    – Duncan X Simpson
    Jul 30 at 17:23















As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
– Duncan X Simpson
Jul 30 at 17:23




As a side note, ssh -t server cmd is a better equivalent to echo cmd|ssh server as without -t, the default for no explicit command (ssh server) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd) is NOT to open one. The -t forces it to open one anyway.
– Duncan X Simpson
Jul 30 at 17:23










1 Answer
1






active

oldest

votes

















up vote
10
down vote



accepted










man ssh documents that:




If a command is specified, it is executed on the remote host instead of a login shell.




The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.



In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.



Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.






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%2f459252%2fconfused-between-echo-command-ssh-server-and-ssh-server-command%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
    10
    down vote



    accepted










    man ssh documents that:




    If a command is specified, it is executed on the remote host instead of a login shell.




    The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.



    In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.



    Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.






    share|improve this answer

























      up vote
      10
      down vote



      accepted










      man ssh documents that:




      If a command is specified, it is executed on the remote host instead of a login shell.




      The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.



      In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.



      Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.






      share|improve this answer























        up vote
        10
        down vote



        accepted







        up vote
        10
        down vote



        accepted






        man ssh documents that:




        If a command is specified, it is executed on the remote host instead of a login shell.




        The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.



        In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.



        Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.






        share|improve this answer













        man ssh documents that:




        If a command is specified, it is executed on the remote host instead of a login shell.




        The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.



        In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.



        Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jul 30 at 5:37









        Michael Homer

        42.1k6107146




        42.1k6107146






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459252%2fconfused-between-echo-command-ssh-server-and-ssh-server-command%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)