Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use tmux on my server and recently I found to my cost that ctrl-d will exit tmux and lose all the session information, my intention was to simply end the ssh session but failed to notice I was still in tmux until too late.

I am aware that I should be careful in future when using ctrl-d but I wondered if there a way to prevent tmux for exiting when hitting ctrl-d by accident? A solution such as a prompt, confirmation or detaching would be fine.

share|improve this question
up vote 21 down vote accepted

To be precise, Ctrld does not exit tmux, but rather a shell. If that shell is running in the only pane of the last window in the tmux session, the session ends and the tmux client exits.

To prevent Ctrld from exiting the shell, you can set the IGNOREEOF shell variable, or set the ignoreeof shell option. Put one of the following in your .bashrc file:

IGNOREEOF=10   # Shell only exists after the 10th consecutive Ctrl-d

set -o ignoreeof  # Same as setting IGNOREEOF=10
share|improve this answer
That is excellent, thanks. I only needed it for tmux so I used set-environment -g 'IGNOREEOF' 2 in .tmux.conf and now I need to hit Ctrl-d 3 times to exit and I am also warned each time with the message: Use "logout" to leave the shell. – Cas Sep 26 '12 at 10:43
Setting IGNOREEOF environment variable have no effect in zsh, but "set -o ignoreeof" or "setopt ignoreeof" does. – sgtpep Apr 24 '13 at 6:19

Besides chepner's answer you can stop the terminal from sending EOF entirely by setting eof to undef with stty:

stty eof undef

Reset with:

stty eof '^d'
share|improve this answer

IGNOREEOF didn't work for me so I just bound Ctrl+D to detach in .tmux.conf:

bind-key -n C-d detach

The -n means no prior escape sequence needed, like the tmux prefix.

share|improve this answer

Your Answer


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.