Operating System - Linux
1819870 Members
2374 Online
109607 Solutions
New Discussion юеВ

Disable Control-C on Linux

 
SOLVED
Go to solution
M.A.
Occasional Advisor

Disable Control-C on Linux

Hi All,

I have created a user TEST. How do i disable the Control-C(to break some operation) button and it should only affect this particular user, and not everybody.

I know we can do that in HPUX, but how is it in Redhat 7.0?

Thank you.

Just ask if you dont know!
7 REPLIES 7
Mark Grant
Honored Contributor
Solution

Re: Disable Control-C on Linux

You can do this in the users .profile with the following near the top

trap "" 2

Of course, you need to make sure that the .profile is read. If they log in via xdm/gdm/kdm and then run some type of terminal, you need to make sure that the terminal is started with a "-ls" to ensure the .profile is read. Anyway, however they log in, put the above in .profile and make sure th e .profile is sourced. If it a normal telnet log in, you won't need to do anything else.
Never preceed any demonstration with anything more predictive than "watch this"
M.A.
Occasional Advisor

Re: Disable Control-C on Linux

Im sorry, but which .profile are you referring to? I tried to find but all i have is .bash_profile. Is this the one?

btw, the user is trying to access using normal telnet from any other server.

TQ.
Just ask if you dont know!
Mobeen_1
Esteemed Contributor

Re: Disable Control-C on Linux

Abdullah,
Mark is talking about the users profile file .profile in the users home directory.

rgds
Mobeen
shetty
Frequent Advisor

Re: Disable Control-C on Linux

Hi Abdullah,
Yeah you are correct, You can find .bash_profile in /home/user_name directory.

There you have to edit as per Mark has said. I hope this will work.

Shetty.
Jan Sladky
Trusted Contributor

Re: Disable Control-C on Linux

hi,
.profile should be placed in $HOME, if is not , create it.

other way how to forbid Ctrl+C is following row in .profile:

stty intr =

(all tty settings you get by stty -a)

br Jan
GSM, Intelligent Networks, UNIX
Stuart Browne
Honored Contributor

Re: Disable Control-C on Linux

Jan has the best idea.

CTRL-C is just the shell sending a signal. All you have to do is stop the shell, which is done through 'stty'. The 'intr' (Interrupt, SIGINT) is what you're trying to stop.

Unfortunately, Jan's post will change the CTRL-C to just the '=' key ;)

To disable it, use the following:

stty intr undef

Put this in '/etc/profile' to disable it for all users, or in the users '.bash_profile' (or '.bashrc') file for an individual user (reccomended).
One long-haired git at your service...
Muthukumar_5
Honored Contributor

Re: Disable Control-C on Linux

hai,

For every user contains .bash_profile file in their home directory to define it's environment variables or settings.

Else copy the root /.bash_profile file to your home directory and change the owner and file permissions.

Control-C is normally known with intr signal. We can remove that signal as

# stty -isig intr
# ^C
After that it will print that control+c value on the screen. It won't do the action.

You can use stty raw intr to do the same effect. But the prompting will be not as like normal

To know more about control+c ,use ksh man page on intr keyword

Regards,
Muthukumar.
Easy to suggest when don't know about the problem!