SSH inside SSH fails with “stdin: is not a tty”












55















I'm trying to connect to machine one with ssh and then connect to another machine two with ssh, but I get this error.



ssh user@computerone.com 'ssh otheruser@computertwo.com'

stdin: is not a tty


Why?










share|improve this question




















  • 1





    I don't think you need those single quotes around the second ssh!

    – coffeMug
    May 9 '16 at 16:19
















55















I'm trying to connect to machine one with ssh and then connect to another machine two with ssh, but I get this error.



ssh user@computerone.com 'ssh otheruser@computertwo.com'

stdin: is not a tty


Why?










share|improve this question




















  • 1





    I don't think you need those single quotes around the second ssh!

    – coffeMug
    May 9 '16 at 16:19














55












55








55


21






I'm trying to connect to machine one with ssh and then connect to another machine two with ssh, but I get this error.



ssh user@computerone.com 'ssh otheruser@computertwo.com'

stdin: is not a tty


Why?










share|improve this question
















I'm trying to connect to machine one with ssh and then connect to another machine two with ssh, but I get this error.



ssh user@computerone.com 'ssh otheruser@computertwo.com'

stdin: is not a tty


Why?







command-line ssh terminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 19 '12 at 0:42









Gilles

542k12810961615




542k12810961615










asked Sep 18 '12 at 15:41









JhonathanJhonathan

1,50731622




1,50731622








  • 1





    I don't think you need those single quotes around the second ssh!

    – coffeMug
    May 9 '16 at 16:19














  • 1





    I don't think you need those single quotes around the second ssh!

    – coffeMug
    May 9 '16 at 16:19








1




1





I don't think you need those single quotes around the second ssh!

– coffeMug
May 9 '16 at 16:19





I don't think you need those single quotes around the second ssh!

– coffeMug
May 9 '16 at 16:19










6 Answers
6






active

oldest

votes


















68














By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. This is the environment provided for the command executed on computerone.



However, when you run ssh without a remote command, it DOES allocate a TTY, because you are likely to be running a shell session. This is expected by the ssh otheruser@computertwo.com command, but because of the previous explanation, there is no TTY available to that command.



If you want a shell on computertwo, use this instead, which will force TTY allocation during remote execution:



ssh -t user@computerone.com 'ssh otheruser@computertwo.com'


This is typically appropriate when you are eventually running a shell or other interactive process at the end of the ssh chain. If you were going to transfer data, it is neither appropriate nor required to add -t, but then every ssh command would contain a data-producing or -consuming command, like:



ssh user@computerone.com 'ssh otheruser@computertwo.com "cat /boot/vmlinuz"'





share|improve this answer

































    9














    There's a better way to use SSH as a relay: use the ProxyCommand option. You'll need to have a key on the client machine that lets you log in into the second computer (public key is the recommended way of using SSH in most circumstances anyway). Put this in your ~/.ssh/config and run ssh computertwo.



    Host computerone
    HostName computerone.com
    UserName user

    Host computertwo
    HostName computertwo.com
    UserName otheruser
    ProxyCommand ssh computerone exec nc %h %p


    nc is netcat. Any of the several versions available will do.






    share|improve this answer
























    • Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

      – Felipe Alvarez
      Jun 26 '14 at 5:07



















    7














    It's expecting an interactive terminal on a tty device on the intermediate server.



    If you try this command, it should work:



    ssh user@computer1 -t "ssh otheruser@computer2"


    See man ssh for the -t option.






    share|improve this answer































      2














      I solved this by adding RequestTTY Yes to my ssh config file located at ~/.ssh/config like this...



      Host myserver.com
      User my-ssh-username
      RequestTTY Yes





      share|improve this answer































        1














        You can use PROXY Jump option in ssh



        -J [user@]host[:port]
        Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified
        separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


        So if I need to connect to hostB but I have to go through hostA first to get there.
        Normally I would



         ssh hostA
        [user@hostA ~]$ ssh hostB


        I now do this



        ssh -J hostA hostB
        [user@hostB ~]$





        share|improve this answer































          0














          You can override an SSH config option "RequestTTY" from the command line.



          My working example cd-serv-one.sh starts /bin/bash in SSH session after running multiple commands:



          #!/bin/bash

          ssh -o "requestTTY=yes" User@ExampleHostName "cd /home/myPathFoo/myPathBar; /bin/bash"


          And now I just run ./cd-serv-one.sh for starting a needed SSH session.






          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%2f48527%2fssh-inside-ssh-fails-with-stdin-is-not-a-tty%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            68














            By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. This is the environment provided for the command executed on computerone.



            However, when you run ssh without a remote command, it DOES allocate a TTY, because you are likely to be running a shell session. This is expected by the ssh otheruser@computertwo.com command, but because of the previous explanation, there is no TTY available to that command.



            If you want a shell on computertwo, use this instead, which will force TTY allocation during remote execution:



            ssh -t user@computerone.com 'ssh otheruser@computertwo.com'


            This is typically appropriate when you are eventually running a shell or other interactive process at the end of the ssh chain. If you were going to transfer data, it is neither appropriate nor required to add -t, but then every ssh command would contain a data-producing or -consuming command, like:



            ssh user@computerone.com 'ssh otheruser@computertwo.com "cat /boot/vmlinuz"'





            share|improve this answer






























              68














              By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. This is the environment provided for the command executed on computerone.



              However, when you run ssh without a remote command, it DOES allocate a TTY, because you are likely to be running a shell session. This is expected by the ssh otheruser@computertwo.com command, but because of the previous explanation, there is no TTY available to that command.



              If you want a shell on computertwo, use this instead, which will force TTY allocation during remote execution:



              ssh -t user@computerone.com 'ssh otheruser@computertwo.com'


              This is typically appropriate when you are eventually running a shell or other interactive process at the end of the ssh chain. If you were going to transfer data, it is neither appropriate nor required to add -t, but then every ssh command would contain a data-producing or -consuming command, like:



              ssh user@computerone.com 'ssh otheruser@computertwo.com "cat /boot/vmlinuz"'





              share|improve this answer




























                68












                68








                68







                By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. This is the environment provided for the command executed on computerone.



                However, when you run ssh without a remote command, it DOES allocate a TTY, because you are likely to be running a shell session. This is expected by the ssh otheruser@computertwo.com command, but because of the previous explanation, there is no TTY available to that command.



                If you want a shell on computertwo, use this instead, which will force TTY allocation during remote execution:



                ssh -t user@computerone.com 'ssh otheruser@computertwo.com'


                This is typically appropriate when you are eventually running a shell or other interactive process at the end of the ssh chain. If you were going to transfer data, it is neither appropriate nor required to add -t, but then every ssh command would contain a data-producing or -consuming command, like:



                ssh user@computerone.com 'ssh otheruser@computertwo.com "cat /boot/vmlinuz"'





                share|improve this answer















                By default, when you run a command on the remote machine using ssh, a TTY is not allocated for the remote session. This lets you transfer binary data, etc. without having to deal with TTY quirks. This is the environment provided for the command executed on computerone.



                However, when you run ssh without a remote command, it DOES allocate a TTY, because you are likely to be running a shell session. This is expected by the ssh otheruser@computertwo.com command, but because of the previous explanation, there is no TTY available to that command.



                If you want a shell on computertwo, use this instead, which will force TTY allocation during remote execution:



                ssh -t user@computerone.com 'ssh otheruser@computertwo.com'


                This is typically appropriate when you are eventually running a shell or other interactive process at the end of the ssh chain. If you were going to transfer data, it is neither appropriate nor required to add -t, but then every ssh command would contain a data-producing or -consuming command, like:



                ssh user@computerone.com 'ssh otheruser@computertwo.com "cat /boot/vmlinuz"'






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 22 at 11:32









                moffeltje

                1033




                1033










                answered Sep 18 '12 at 15:57









                mrbmrb

                7,56912533




                7,56912533

























                    9














                    There's a better way to use SSH as a relay: use the ProxyCommand option. You'll need to have a key on the client machine that lets you log in into the second computer (public key is the recommended way of using SSH in most circumstances anyway). Put this in your ~/.ssh/config and run ssh computertwo.



                    Host computerone
                    HostName computerone.com
                    UserName user

                    Host computertwo
                    HostName computertwo.com
                    UserName otheruser
                    ProxyCommand ssh computerone exec nc %h %p


                    nc is netcat. Any of the several versions available will do.






                    share|improve this answer
























                    • Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                      – Felipe Alvarez
                      Jun 26 '14 at 5:07
















                    9














                    There's a better way to use SSH as a relay: use the ProxyCommand option. You'll need to have a key on the client machine that lets you log in into the second computer (public key is the recommended way of using SSH in most circumstances anyway). Put this in your ~/.ssh/config and run ssh computertwo.



                    Host computerone
                    HostName computerone.com
                    UserName user

                    Host computertwo
                    HostName computertwo.com
                    UserName otheruser
                    ProxyCommand ssh computerone exec nc %h %p


                    nc is netcat. Any of the several versions available will do.






                    share|improve this answer
























                    • Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                      – Felipe Alvarez
                      Jun 26 '14 at 5:07














                    9












                    9








                    9







                    There's a better way to use SSH as a relay: use the ProxyCommand option. You'll need to have a key on the client machine that lets you log in into the second computer (public key is the recommended way of using SSH in most circumstances anyway). Put this in your ~/.ssh/config and run ssh computertwo.



                    Host computerone
                    HostName computerone.com
                    UserName user

                    Host computertwo
                    HostName computertwo.com
                    UserName otheruser
                    ProxyCommand ssh computerone exec nc %h %p


                    nc is netcat. Any of the several versions available will do.






                    share|improve this answer













                    There's a better way to use SSH as a relay: use the ProxyCommand option. You'll need to have a key on the client machine that lets you log in into the second computer (public key is the recommended way of using SSH in most circumstances anyway). Put this in your ~/.ssh/config and run ssh computertwo.



                    Host computerone
                    HostName computerone.com
                    UserName user

                    Host computertwo
                    HostName computertwo.com
                    UserName otheruser
                    ProxyCommand ssh computerone exec nc %h %p


                    nc is netcat. Any of the several versions available will do.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 19 '12 at 0:56









                    GillesGilles

                    542k12810961615




                    542k12810961615













                    • Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                      – Felipe Alvarez
                      Jun 26 '14 at 5:07



















                    • Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                      – Felipe Alvarez
                      Jun 26 '14 at 5:07

















                    Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                    – Felipe Alvarez
                    Jun 26 '14 at 5:07





                    Aren't we required to add a "proxy"-related line into 'authorized_keys' on computerone? I keep meaning to look into the 'proxy' power of openSSH, but just haven't gotten around to it yet.

                    – Felipe Alvarez
                    Jun 26 '14 at 5:07











                    7














                    It's expecting an interactive terminal on a tty device on the intermediate server.



                    If you try this command, it should work:



                    ssh user@computer1 -t "ssh otheruser@computer2"


                    See man ssh for the -t option.






                    share|improve this answer




























                      7














                      It's expecting an interactive terminal on a tty device on the intermediate server.



                      If you try this command, it should work:



                      ssh user@computer1 -t "ssh otheruser@computer2"


                      See man ssh for the -t option.






                      share|improve this answer


























                        7












                        7








                        7







                        It's expecting an interactive terminal on a tty device on the intermediate server.



                        If you try this command, it should work:



                        ssh user@computer1 -t "ssh otheruser@computer2"


                        See man ssh for the -t option.






                        share|improve this answer













                        It's expecting an interactive terminal on a tty device on the intermediate server.



                        If you try this command, it should work:



                        ssh user@computer1 -t "ssh otheruser@computer2"


                        See man ssh for the -t option.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 18 '12 at 15:56









                        roknirroknir

                        1963




                        1963























                            2














                            I solved this by adding RequestTTY Yes to my ssh config file located at ~/.ssh/config like this...



                            Host myserver.com
                            User my-ssh-username
                            RequestTTY Yes





                            share|improve this answer




























                              2














                              I solved this by adding RequestTTY Yes to my ssh config file located at ~/.ssh/config like this...



                              Host myserver.com
                              User my-ssh-username
                              RequestTTY Yes





                              share|improve this answer


























                                2












                                2








                                2







                                I solved this by adding RequestTTY Yes to my ssh config file located at ~/.ssh/config like this...



                                Host myserver.com
                                User my-ssh-username
                                RequestTTY Yes





                                share|improve this answer













                                I solved this by adding RequestTTY Yes to my ssh config file located at ~/.ssh/config like this...



                                Host myserver.com
                                User my-ssh-username
                                RequestTTY Yes






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered May 9 '16 at 15:43









                                JohnJohn

                                1211




                                1211























                                    1














                                    You can use PROXY Jump option in ssh



                                    -J [user@]host[:port]
                                    Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified
                                    separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


                                    So if I need to connect to hostB but I have to go through hostA first to get there.
                                    Normally I would



                                     ssh hostA
                                    [user@hostA ~]$ ssh hostB


                                    I now do this



                                    ssh -J hostA hostB
                                    [user@hostB ~]$





                                    share|improve this answer




























                                      1














                                      You can use PROXY Jump option in ssh



                                      -J [user@]host[:port]
                                      Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified
                                      separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


                                      So if I need to connect to hostB but I have to go through hostA first to get there.
                                      Normally I would



                                       ssh hostA
                                      [user@hostA ~]$ ssh hostB


                                      I now do this



                                      ssh -J hostA hostB
                                      [user@hostB ~]$





                                      share|improve this answer


























                                        1












                                        1








                                        1







                                        You can use PROXY Jump option in ssh



                                        -J [user@]host[:port]
                                        Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified
                                        separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


                                        So if I need to connect to hostB but I have to go through hostA first to get there.
                                        Normally I would



                                         ssh hostA
                                        [user@hostA ~]$ ssh hostB


                                        I now do this



                                        ssh -J hostA hostB
                                        [user@hostB ~]$





                                        share|improve this answer













                                        You can use PROXY Jump option in ssh



                                        -J [user@]host[:port]
                                        Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified
                                        separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


                                        So if I need to connect to hostB but I have to go through hostA first to get there.
                                        Normally I would



                                         ssh hostA
                                        [user@hostA ~]$ ssh hostB


                                        I now do this



                                        ssh -J hostA hostB
                                        [user@hostB ~]$






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jan 31 '18 at 9:29









                                        nelaaronelaaro

                                        5902716




                                        5902716























                                            0














                                            You can override an SSH config option "RequestTTY" from the command line.



                                            My working example cd-serv-one.sh starts /bin/bash in SSH session after running multiple commands:



                                            #!/bin/bash

                                            ssh -o "requestTTY=yes" User@ExampleHostName "cd /home/myPathFoo/myPathBar; /bin/bash"


                                            And now I just run ./cd-serv-one.sh for starting a needed SSH session.






                                            share|improve this answer




























                                              0














                                              You can override an SSH config option "RequestTTY" from the command line.



                                              My working example cd-serv-one.sh starts /bin/bash in SSH session after running multiple commands:



                                              #!/bin/bash

                                              ssh -o "requestTTY=yes" User@ExampleHostName "cd /home/myPathFoo/myPathBar; /bin/bash"


                                              And now I just run ./cd-serv-one.sh for starting a needed SSH session.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                You can override an SSH config option "RequestTTY" from the command line.



                                                My working example cd-serv-one.sh starts /bin/bash in SSH session after running multiple commands:



                                                #!/bin/bash

                                                ssh -o "requestTTY=yes" User@ExampleHostName "cd /home/myPathFoo/myPathBar; /bin/bash"


                                                And now I just run ./cd-serv-one.sh for starting a needed SSH session.






                                                share|improve this answer













                                                You can override an SSH config option "RequestTTY" from the command line.



                                                My working example cd-serv-one.sh starts /bin/bash in SSH session after running multiple commands:



                                                #!/bin/bash

                                                ssh -o "requestTTY=yes" User@ExampleHostName "cd /home/myPathFoo/myPathBar; /bin/bash"


                                                And now I just run ./cd-serv-one.sh for starting a needed SSH session.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Feb 28 at 7:33









                                                xorDivxorDiv

                                                1




                                                1






























                                                    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%2f48527%2fssh-inside-ssh-fails-with-stdin-is-not-a-tty%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 reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                                    is 'sed' thread safe

                                                    How to make a Squid Proxy server?