0

I wanted to execute a command in a remote shell in its interactive environment, so as to make it load my remote .bash_profile there first before executing the command.

This works great:

  • echo "command" | ssh user@remote_host [1]

But it gives an error

Pseudo-terminal will not be allocated because stdin is not a terminal.

I don't know if this is an issue because the above command works great for my purpose, but still I looked for a solution to make it go away and I found

  • ssh -t -t [2]

Combining them you get echo "command" | ssh -tt user@remote_host which works great.

But for some weird reason on Git bash, after returning from executing the command, I can't type anymore. I tested it on Cygwin where it works great, so it's only Git bash that has this problem.

I tried to type exit in case it's still invisibly stuck in that remote shell but nothing works.

Any ideas what might be the issue with doing ssh -tt on Git bash?

2

The "Pseudo-terminal will not be allocated" message is just informational. If the command you're running doesn't need a terminal, you'd be better off running ssh with the -T option to disable PTY allocation and shut up the message.

It sounds like your local TTY is being left in a wierd state for some reason. Running stty sane should reset the terminal to a usable state. I know you said you can't type, but you could try doing this:

  1. Type Control-Q (that is, hold down your "Control" key and hit "Q") to cancel any Ctrl-S/Ctrl-Q suspend that might be in place
  2. Type Control-J. This is a literal newline character to make sure the shell is ready to read a new command line.
  3. type "stty sane" then Control-J again. Try it even if what you type isn't appearing on the screen.

If that doesn't work, the nuclear option would be to run "stty sane" on the stuck TTY from another terminal.

  1. Open another terminal window.
  2. Use "ps" to figure out what PTY the stuck session is on.
  3. Run stty sane with input redirected from the PTY.

For example, on Linux:

$ ps -fu jdoe
...
jdoe   2083  2080  0 22:17 pts/0    00:00:00 /bin/bash  <-- TTY is "/dev/pts/0"
$ stty sane < /dev/pts/0
  • Thanks so much for this. I kept getting into this weird state after git add -i. Had no idea what was going on. – leesio Oct 25 '17 at 8:01

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.