I'm facing a really frustrating problem on this specific server, every time I press ctrl+c, I logout from the root session

Running CentOS Linux release 7.3.1611 & Bash (4.2.46-21.el7_3.x86_64)

[root@server ~]# uname -a  
Linux server 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux  
[root@server ~]# ^C   
[root@server ~]# logout
[user@server ~]$   
  • That's not the default; what shell settings have been made in e.g. .bashrc and other init files? – thrig Aug 9 '17 at 15:18
  • What is root's login shell? getent passwd root – glenn jackman Aug 9 '17 at 16:35
  • What command do you use to become root? – Mark Plotnick Aug 10 '17 at 1:48

trapping-ctrl-c-in-bash describe how to trap CTRL+C in order to trigger some action.
Please check in your root account (bashrc etc), if you are running similar trap to force logout when pressing CTRL+C

Trapping ctrl-c in Bash

You can use the trap builtin to handle a user pressing ctrl-c during the execution of a Bash script. e.g. if you need to perform some cleanup functions.


# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

function ctrl_c() {
        echo "** Trapped CTRL-C"

for i in `seq 1 5`; do
    sleep 1
    echo -n "."

You might check if your bash environment isn't actually a wrapper around bash that just runs bash below.

We use a similiar solution on our workplace and it is used to track everything done using SSH, however the problem is exactly as yours, whenever ctrl+c is involved it likes to drop out of shell.


In every OS you can find Signals which should be handled . There is three reactions to signals : 1 - ignore it , 2 - handle it by yourself , 3- leave it to OS . Ctrl + C is hangup signal by default . you use trap command to handle signal . also check ASCII standard on your system , some coding maybe different. check man ascii for HUP sign and its belongs charterer. trap command example: trap "echo hi" SIGINT which print hi every time you press Ctrl + C . Also you can find list of signal by the command of kill -l .

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.