I regularly ssh to a centos 5 box. Somehow they keys are mapped so that control+d will log me out of my current shell. If I am sudo'ed to another use it puts me back to the previous user. If I am not sudo'ed it just disconnects me. How can I keep this from happening? I regularly use control+d to cancel out of the python interpreter and sometimes I accidentally press it more than once.


4 Answers 4


You're looking for the IGNOREEOF environment variable if you use bash:


Controls the action of an interactive shell on receipt of an EOF character as the sole input. If set, the value is the number of consecutive EOF characters which must be typed as the first characters on an input line before bash exits. If the variable exists but does not have a numeric value, or has no value, the default value is 10. If it does not exist, EOF signifies the end of input to the shell.

So export IGNOREEOF=42 and you'll have to press Ctrl+D fourty-two times before it actually quits your shell.

POSIX set has an -o ignoreeof setting too. So consult your shell's documentation to see if your shell has this (it should), and to check its exact semantics.

  • Nice, gives a "Use exit to leave the shell" message, at least on Ubuntu. Being su'd into a user, you probably don't want to inadvertently leave it, esp if the parent user is root level. Dec 24, 2011 at 19:54
  • 2
    I personally find that really annoying, so I don't set it anywhere. Found out about these while trying to disable that behavior :)
    – Mat
    Dec 24, 2011 at 19:59
  • 3
    I can't resist being a pedant. IGNOREEOF is the number of times the EOF is ignored before finally accepting it. So in your example above, if you export IGNOREEOF=42, you will need to press CONTROL-D 43 times to exit--not 42. Feb 7, 2018 at 15:05

If you really don't like having Ctrl-d, then you could remove the eof character in the terminal controls.

stty eof undef

After this, Cntl-d will be any other control character.

  • 1
    I just tried that in a terminal (urxvt) with bash, and in a plain console, and it did not work.
    – Mat
    Dec 24, 2011 at 19:56
  • Hmm... that used to work and docs still say that it does. An alternative would be to use <kbd>Ctrl-[</kvd>.
    – Arcege
    Dec 24, 2011 at 20:30
  • 2
    This would also make it no longer exit from python.
    – psusi
    Dec 27, 2011 at 16:04
  • Now Ctrl-d returns: zsh: do you wish to see all 5980 possibilities @Arcege
    – alper
    Mar 16, 2020 at 15:19

tcsh set ignoreeof or set ignoreeof=<any value not 1> works


The Bug

I had a similar problem, if I used Ctrl+D to debug and happened to use it one extra time than intended it closed the whole tab.

Suggestion Using Environment Variables

Temporary (only for your current session):

export IGNOREEOF=20


set ignoreeof=20

After setting it, you can print to check if it got set:


You can also unset it:

unset ignoreeof


Open, edit and set the environment variable for good, for example using sublime

subl ~/.bashrc or subl ~/.bash_profile and add export IGNOREEOF=15 at the end of the file to set the environmental variables permanently. To do that automatically you can try this in you console:

echo "export IGNOREEOF=20" >> ~/.bash_profile

You can also check the current value by using echo like this:


If you have set the value correctly, it should print the value to your terminal. If the value is not set, it will just print an empty line.


Try this:

export IGNOREEOF=20 && echo "export IGNOREEOF=20" >> ~/.bash_profile

Hope this helps, have a great day!

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.