52

I am often logged in several SSH sessions at once. To logout from several sessions, I press CTRL+d, until I am back on my local machine.

However, I occasionally press it once too many, and my terminal exits.

Is there a way to make CTRL+d unable to close my terminal ?

I am using terminator as my terminal emulator.

3
60

You can also disable eof generally in bash:

set -o ignoreeof

4
  • 2
    But if you do that indiscriminately, it'll apply when logged in over ssh as well. Jun 25 '14 at 23:17
  • 3
    I'm using terminator 0.97. When I do set -o ignoreeof, it blocks ctrl-d (doesn't exit) 10 times with a message: Use "exit" to leave the shell. On the 11th ctrl-d, it exits. Jan 5 '17 at 20:33
  • OMG, thank you!! That (accidental terminal cloures) was a huge annoyance for me. Added to ~/.bashrc; works in konsole | xfce4-terminal | ... :-D Apr 19 '18 at 20:12
  • @Gilles Good input, do you have a solution for that?
    – Gauthier
    Feb 13 '19 at 12:52
41

You can use the IGNOREEOF environment variable in bash. So export IGNOREEOF=42 and you'll have to press Ctrl+D forty-two times before it actually quits your shell.

POSIX set has an -o ignoreeof setting too.

5
  • 7
    Forty-three times: the first forty-two are ignored, and the last one actually quits. :-)
    – deltab
    Jun 25 '14 at 15:49
  • I figured Forty-three times would be too redundant. Definately the set -o ignoreeof would be more practical
    – ryekayo
    Jun 25 '14 at 15:57
  • 3
    But if you do that indiscriminately, it'll apply when logged in over ssh as well. Jun 25 '14 at 23:17
  • But you have to write the command every time you open a terminal.How do you disable this permanently?
    – MycrofD
    Oct 12 '14 at 7:05
  • 3
    @MycrofD Add this to your .bashrc or .profile. May 21 '15 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.