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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="354046504775565a5845404150475a5b501b565a58">[email protected]</a> 'ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b041f030e191e180e192b0804061b1e1f0e191f1c0445080406">[email protected]</a>' stdin: is not a tty
Why?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 [email protected] 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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee9b9d8b9cae8d81839e9b9a8b9c81808bc08d8183">[email protected]</a> 'ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a9b2aea3b4b3b5a3b486a5a9abb6b3b2a3b4b2b1a9e8a5a9ab">[email protected]</a>'
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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e396908691a3808c8e93969786918c8d86cd808c8e">[email protected]</a> 'ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="630c170b06111610061123000c0e131617061117140c4d000c0e">[email protected]</a> "cat /boot/vmlinuz"'
Method 2
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 User user Host computertwo HostName computertwo.com User otheruser ProxyCommand ssh computerone exec nc %h %p
nc is netcat. Any of the several versions available will do.
Method 3
It’s expecting an interactive terminal on a tty device on the intermediate server.
If you try this command, it should work:
ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a4f495f487a5955574a4f4e5f480b">[email protected]</a> -t "ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93fce7fbf6e1e6e0f6e1d3f0fcfee3e6e7f6e1a1">[email protected]</a>"
See man ssh for the -t option.
Method 4
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
Method 5
You can use PROXY Jump option in ssh
-J [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a6a0b6a193">[email protected]</a>]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 [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4336302631032b2c303702">[email protected]</a> ~]$ ssh hostB
I now do this
ssh -J hostA hostB [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b2e283e291b3334282f19">[email protected]</a> ~]$
You could even , separate multiple hosts
ssh -J hostA,hostB hostC [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b6b0a6b183abacb0b780">[email protected]</a>]
Much simpler than trying -t to run ssh command again.
Method 6
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" <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99cceafcebd9dce1f8f4e9f5fcd1f6eaedd7f8f4fc">[email protected]</a> "cd /home/myPathFoo/myPathBar; /bin/bash"
And now I just run ./cd-serv-one.sh for starting a needed SSH session.
Method 7
You should fix the rc files on computerone! One of them (probably .bashrc) contains mesg y or mesg n without first checking whether stdin is a tty.
You should replace mesg n by [ -t 0 ] && mesg y.
References: man 1 test
0 is the file number of stdin.
Background: While ssh <host> does allocate a pseudo tty on , ssh <host> <cmd> (without option -l) does not. Still, some programs (mesg, editors, password prompts) need a terminal (or a pseudo terminal).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0