How can I disable the key combination Ctrl+C on GNU-screen? Actually I would have to get used to it, but I press Ctrl+C rather than Ctrl+A+D out of habit.
3 Answers
Now I've found the answer myself. The instructions
defscrollback 30000
bindkey "^C" echo 'Blocked. Please use [Ctrl]+[A] + [Ctrl]+[Enter] + [Y]'
bindkey "^D" echo 'Blocked. Please use [Ctrl]+[A] + [Ctrl]+[Enter] + [Y]'
bind "^M" quit
in the file
~/.screenrc
lead to the fact that C-c only executes the echo
command, thus no longer sends an interrupt. Instead you can stop the screen with ^M
or Ctrl+Enter. Because I use bind
(unlike bindkey
) you have to press C-a first. The confirmation prompt can be confirmed with Y. The advantage of this solution is that I don't have to change the actual Java or Python program. Please remember that running screen sessions must be restarted in order to read the new ~/.screenrc
file. (This path depends on the user, e.g. /root/.screenrc
or /home/user/.screenrc
.)
Helpful links:
- Docu: http://web.mit.edu/gnu/doc/html/screen_13.html
- Find your own key combination: https://unix.stackexchange.com/a/116588/239596
Tested with
- Screen version 4.01.00devel (GNU) 2-May-06
- Ubuntu 14.04.5 LTS
- MobaXterm v10.9 Build 3656 (Windows)

- 308
Ctrl+C sends the INT
(interrupt) signal to the process currently in the foreground. This is an important signal to be able to send, so the best thing would be to just learn not to press that key combination by mistake.
You can also remap that key combination so that you have another control sequence that sends the INT
signal. For example, you may make Ctrl+G do the same thing with the shell command
stty intr ^G
The Ctrl+C key combination will then just send a character with ASCII code 3.
Again, it would probably be less problematic to just learn to use Ctrl+C correctly.

- 333,661
You can avoid this issue in the first place by using logging as follows:
- While creating the screen, use this command to generate a log file:
screen -L -Logfile file_name.log
- Now, to check the screen, do not resume it; instead read the log file interactively, with one of these two commands:
tail -f -n 20 file_name.log
watch tail file_name.log
Hope this helps.

- 13
-
Well, just as I have the habit of pressing [Ctrl]+[C], I have the habit of going in with
screen -r
, so your solution is only something for disciplined people - who don't exist. ;) My point is not to avoid the error, but to prevent it. ;D – uav Jul 26 '21 at 13:06
INT
signal completely. – Kusalananda Dec 17 '18 at 11:20