Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 11 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
1  
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
2  
Setting IGNOREEOF environment variable have no effect in zsh, but "set -o ignoreeof" or "setopt ignoreeof" does. –  sgtpep Apr 24 '13 at 6:19
add comment

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
add comment

Your Answer

 
discard

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.