LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2006, 12:54 PM   #1
fobster
LQ Newbie
 
Registered: Jan 2006
Location: ca, usa
Distribution: rh9
Posts: 12

Rep: Reputation: 0
how do i execute binary on ssh login?


I have a program that grabs info from the database and displays it. I created a new user account. The only function of this user account is to execute that program automatically when someone login with this account through ssh. If the program ends or if the user quits the program, the user should be logged out of ssh too. Basically, I dont want ppl to have shell access but just to run this program. How would i accomplish this?

TIA

fobster
 
Old 05-26-2006, 01:05 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
You could set the ~/.bash_profile for the userid to something like:

Code:
function Cleanup_And_Exit_On_Interrupt () {
   logout
}
trap Cleanup_And_Exit_On_Interrupt INT
trap Cleanup_And_Exit_On_Interrupt HUP
trap Cleanup_And_Exit_On_Interrupt QUIT
trap Cleanup_And_Exit_On_Interrupt USR1
trap Cleanup_And_Exit_On_Interrupt TERM

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

someprogram
exit
You could also set their shell to a script that just runs the program and logs out.

Last edited by macemoneta; 05-26-2006 at 01:07 PM.
 
Old 05-26-2006, 01:47 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
You could also setup ssh to require pubkey authentication and then use "forced commands" specified in the user's authorized_keys2 file. But macemoneta's suggestion is probably simpler and easier to understand. You could also just setup "/path/to/someprogram" as the shell for the restricted user. Double verify there are no shell escapes in someprogram!!!

Something like this in /etc/passwd:
Code:
username:x:1000:1000:User name and phone number:/dev/null:/path/to/someprogram
I'm not sure if you can specify /dev/null as a user's HOME directory. Never tried that. Sounds like a good idea to try, if it works!
 
Old 05-26-2006, 05:04 PM   #4
fobster
LQ Newbie
 
Registered: Jan 2006
Location: ca, usa
Distribution: rh9
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by haertig
You could also setup ssh to require pubkey authentication and then use "forced commands" specified in the user's authorized_keys2 file. But macemoneta's suggestion is probably simpler and easier to understand. You could also just setup "/path/to/someprogram" as the shell for the restricted user. Double verify there are no shell escapes in someprogram!!!

Something like this in /etc/passwd:
Code:
username:x:1000:1000:User name and phone number:/dev/null:/path/to/someprogram
I'm not sure if you can specify /dev/null as a user's HOME directory. Never tried that. Sounds like a good idea to try, if it works!

thanks haertig, modifying /etc/passwd worked, is there anyway to prevent the user from killing the program with Ctrl-C??
 
Old 05-26-2006, 05:46 PM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by fobster
thanks haertig, modifying /etc/passwd worked, is there anyway to prevent the user from killing the program with Ctrl-C??
If you're wanting to do this for security reasons, don't bother. Once that program exits, for any reason - normal exit, ctrl-c, etc., - they are logged off. That's why we put it into /etc/passwd as their shell. Normally, a user has a regular shell defined in /etc/password, bash is typical for Linux, and when they exit a program they are dropped back into their shell.

But if the program IS their shell, there's nowhere to drop back to, so they are logged off. Nice and secure.

Last edited by haertig; 05-26-2006 at 05:48 PM.
 
Old 05-26-2006, 06:00 PM   #6
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
p.s. - Even though this is exactly what I told you to do, it is generally considered a no-no to manually edit your /etc/passwd file. This is because if you screw up your editing and corrupt the file, you may lock yourself out of your system. It's always good to have Knoppix or another LiveCD handly to boot with should you need to save yourself from an editing mistake in a critical file such as this.

That being said, I edit important system files manually all the time. /etc/inittab, /etc/fstab, /etc/X11/xorg.conf, ... etc. I've got backups, and LiveCD's are kept handy for recovery.
 
  


Reply

Tags
login



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Execute Binary rightsidedown Linux - Software 8 05-10-2011 12:41 AM
/etc/rc.d/rc.6: cannot execute binary file __spc__ Linux - General 11 04-17-2006 11:12 AM
.bashrc doesn't execute on ssh login rose_bud4201 Linux - Software 2 06-01-2005 08:28 AM
Cannot execute binary file??? Wimpie22 Linux - General 3 01-11-2004 04:38 PM
Cannot execute binary file Bigun Linux - Software 17 11-03-2002 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration