Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

3 Answers 3

up vote 29 down vote accepted

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

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 at 5:07

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.