How can I prevent tmux exiting with Ctrl-d?

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.


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

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.