Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a program which uses python's cmd module for command line interfaces.

Now I want it to run on my Linux server whenever any normal user logs in to it, in a way that user never gets the default Linux prompt (i.e he should not be able to kill the program or send it to background or any such stuff).

For security issues the program should never allow user to gain access of normal prompt. The user should always use program's cmdline to fire all commands. (The program has various filters built in it).

Tried putting the program execution command in /etc/password (replacing default bash shell with the program execution cmd) for the user & also tried to put it in users .bashrc file, but of no use; user can still gain access default prompt.

Any pointers for this can very helpful.

share|improve this question
1  
Not 100% sure, but try this: Write a shell script that starts python using the required parameters. Save as /bin/pythonsh, make executable and fix permissions. Add to /etc/shells. Select it as login shell for the user (using chsh). –  Daniel Beck Mar 2 '12 at 7:47
2  
If the user only logs in via SSH, you can also use OpenSSH's ForceCommand to run python [...]; exit, so that python always is launched and that the user automatically exists upon quitting or suspending it. –  Daniel Beck Mar 2 '12 at 7:49
    
@DanielBeck: yes user will only access the server via ssh –  avasal Mar 2 '12 at 7:57
    
@Daniel: thanks, Force command seems to do the job for me :) –  avasal Mar 14 '12 at 4:11
    
Consider posting the exact details as an answer as reference to others in a similar situation. "Just use ForceCommand" might not cut it. Since I've never used it that way, I'd also like to see it. Thanks. –  Daniel Beck Mar 14 '12 at 6:50

1 Answer 1

You can replace SHELL=/bin/sh with your script in /etc/profile (or equivalent for ssh logins)- most terminal emulators and many other apps will probe env to get this value to run the default shell, but will fall back to /bin/sh or /bin/bash if it fails (you may want to allow yourself to use the shell though, so wrap it in a user/gid/uid check)

use a shell script instead (or just add it to the bottom of the bashrc without the header)

#!/bin/sh
#public domain fake shell
while read -p "$PS1" CMD; do
   case "$CMD" in
      *exit*|*bad_case*|*another bad case*)echo bad command: user info logged etc..;;
      *good case*|*another good case*|*more*)eval "$CMD";;
      *)echo command not supported;;
   esac
done

or change permissions on the shell - but be prepared for random things to not work if you have to go that far

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.