43

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

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

Is there a way to block CTRL+d from closing my terminal ?

I am using terminator as my terminal emulator

44

You can also disable eof generally in bash:

set -o ignoreeof

  • 2
    But if you do that indiscriminately, it'll apply when logged in over ssh as well. – Gilles Jun 25 '14 at 23:17
  • 2
    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. – AAAfarmclub 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 – Victoria Stuart Apr 19 '18 at 20:12
  • @Gilles Good input, do you have a solution for that? – Gauthier Feb 13 at 12:52
31

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.

  • 2
    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. – Gilles 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
  • 2
    @MycrofD Add this to your .bashrc or .profile. – Jan Warchoł May 21 '15 at 14:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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