I'm experiencing a bizarre problem with SSH + Bash + Terminal.app: when SSH is run in the background, the shell appears to randomly lose keypresses ~50% of the time.
For example, if I run:
$ ssh -N my-tunnel &
$ # typing becomes lossy
Then type "asdf", only the letters "a" and "f" might show up (although this is random and partially related typing speed; if I was typing at full speed, possibly only the "f" might appear).
This problem only affects the shell. If I run, for example, ssh -N my-tunnel & cat
, characters are echoed as expected from cat. Key presses are lost once cat is killed and I'm back at the shell.
Other things to note:
- Other terminal windows are unaffected
- The shell returns to normal as soon as ssh is terminated
- Using
nohup ssh -N my-tunnel &
doesn't change anything
So: what's going on here? And is there any way I can background ssh without breaking the terminal?
Best Answer
You should be using
-n
in addition to-N
to prevent ssh from reading from the terminal.