1844038 Members
2280 Online
110226 Solutions
New Discussion

Restrict shell to user

 
Isaac_4
Frequent Advisor

Restrict shell to user

Hi:

I dont whant the users can use CTRL+D o CRTL+C to cancel a program that they run. rigth now the user made a ctrl+d and they go to unix shell but i need a exit complete when they try to type a crtl + d to break a program.
Some Body have a idea ?

thank alot !!
The time is gold
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Restrict shell to user

Hi Isaac:

Generally, a CTRL_D signals end-of-file for a read operation. A CTRL_C is a an interrupt signal. In a shell program you use 'trap' do catch and deal with the signal. For instance:

#!/usr/bin/sh
trap 'echo "No way!"' INT
read REPLY
echo ${REPLY}
exit

Regards!

...JRF...
Roboz
Frequent Advisor

Re: Restrict shell to user

Hello Isaac,

There are a couple of alternate solutions you may want to try:

1) Use the â execâ command to execute the user application from the user environment start up. This will still allow the user to CTRL_C or CTRL-D but will not allow them to obtain a shell prompt.
Example:

edit the users $HOME/.profile file (for the bourne/ksh/posix shells) or $HOME/.login (for the Csh) and add the following lines in an appropriate place within the file.

exec ; exit


2) You can substitute the star up shell in the /etc/passwd file for the user with a start up scrip that will ignore signals from the keyboard.
Example:
Start up script for a posix shell:
----------------
#!/usr/bin/sh
export PATH=$PATH: #usually /usr/local/bin
trap â â 1 2 3 15 # this will ignore keyboard signal as well as kill â s TERM

exec exit
-------------------------------
Then edit the /etc/passwd file and change the last field of the userâ s record (i.e /usr/bin/sh) by the full pathname of your start up script. This will create a slave user (slave to the application that is) the upon login in will be presented with the application, attempts to stop the scrip will fail and closing the application by any means will log out the user.

3) You can also use the command â styâ to disable the â suspâ , â intâ and â quitâ signals from being generated via keyboard. That is disable CTRL-D, CTRL-C and CTRL- \

I hope this will help you some how, good luck