when i do ssh host it will log me in to host and then run bash. but when i do ssh host bash it will just sit there doing seemingly nothing. to get a usable bash prompt i have to provide -t like this: ssh -t host bash.

actually it does not just sit there doing nothing. when i do ssh host bash (without -t) it seems that i get a working bash but no prompt. i can do commands like echo foo or ps -ef and will get usable output. just no prompt.

why do i need -t for ssh host bash to get a usable bash prompt but ssh host runs bash just fine?


When you run:

ssh host some    command

ssh doesn't request a pseudo-tty device to be used on the remote end. The stdout and stderr or the remote commands are pipes instead. sshd runs:

exec("remote-user-login-shell", ["remote-user-login-shell", "-c", "some command"])

That's the rsh mode. When you don't specify a command, it enters the rlogin mode, where it does start a pseudo-terminal, and runs a login interactive shell session, where it runs:

exec("remote-user-login-shell", ["-remote-user-login-shell"])

(with a leading - in the argv[0] to tell the shell it is to behave as a login shell).

You need -t when you need to run a specific command interactively (like bash or vi) in which case sshd does create a pseudo-terminal on the remote host to interact with the remote command. If not, you do not want to use -t.


ssh host bash

bash doesn't do nothing, it's just not interactive. It will process the input the same way as it would process a script or like you would get by running cat | bash. You can still enter commands and see their output.

Historically, rsh (which ssh replaced) was actually running rlogin when not given any command to run, and rlogin was invoking a different service (on a different TCP port) from the rsh service.

| improve this answer | |
  • Can the answer explain what a "remote tty" is? – fraxture Jul 29 '19 at 14:42
  • @fraxture, see edit where I've tried to make the wording more consistent. – Stéphane Chazelas Jul 29 '19 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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