tmux "open terminal failed: not a terminal" and bash "no job control in this shell" over SSH
Both mean the command got no terminal: ssh host command does not ask for one. Add -t, or -tt from a script, or start tmux detached with new -d.
You run a program on a host in one step, for example ssh [email protected] tmux attach, and it fails right away:
open terminal failed: not a terminal
Or you run an interactive bash the same way, ssh [email protected] 'bash -ic mycommand', and two lines come first:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
Both have the same cause. When you give ssh a command, it does not ask the host for a terminal (a pty) unless you tell it to. The program on the host then has plain pipes for input and output instead of a terminal.
Why each program complains
- tmux draws a full screen and reads single keys, so it needs a terminal. Without one, the client stops with "open terminal failed: not a terminal".
- bash -i is an interactive shell, and job control (Ctrl+Z,
fg,bg) is on by default in an interactive shell. Job control works through the terminal's process groups, so without a terminal bash prints the two warnings, goes on without job control, and still runs the command.
The fix: ask for a terminal
Add -t:
ssh -t [email protected] tmux attach
ssh -t [email protected] 'bash -ic mycommand'
-tasks for a terminal, but only if your own side has one. Run from a script or a pipe, ssh then prints "Pseudo-terminal will not be allocated because stdin is not a terminal." and carries on without one.-ttforces a terminal even then.- In
~/.ssh/config,RequestTTY yesacts like-t, andRequestTTY forcelike-tt.
If the host refuses the terminal you asked for, see SSH "PTY allocation request failed on channel 0".
When you do not need a terminal
- Start tmux without attaching.
tmux new-session -d -s job1 'long-command'creates a detached session and needs no terminal, so it works in a plainssh host command, a script or cron. Attach later from an interactive login. - Do not use bash -i just for aliases or PATH. People add
-iso that~/.bashrcis read. Put what the command needs in the command itself, or see Command not found with "ssh host command" but it works after logging in: PATH and .bashrc.
Related
- SSH "PTY allocation request failed on channel 0"
- sudo "a terminal is required to read the password" when running a command over SSH
- Command not found with "ssh host command" but it works after logging in: PATH and .bashrc
- Keep your work after a disconnect with tmux, and attach automatically
- Ctrl+Z and "Stopped": get the program back with fg, bg and jobs