Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run an application on a Linux machine which will be accessed by most users using PuTTY. I want to start that app and, when it's done, I want it to end the SSH session. Is it secure/sufficient to use chsh to set their shell to the app? Do I need to do anything else (chroot jail)? This will be implemented on Ubuntu Lucid.

share|improve this question
up vote 6 down vote accepted

Tacking onto ErikA's suggestion. You do not need to use keys to use the force command.

You can also specify something like this in your sshd_config.

Match User xxxx
    ForceCommand /usr/bin/nnnn

Match Group yyyy
    ForceCommand /usr/bin/nnnn

The one important bit is that you will need to check is to see if the application you force allows the user to actually start another shell or process.

share|improve this answer
Ooh, didn't know that. Good to know! – EEAA Sep 28 '10 at 20:11
Excellent, thanks! – syrion Sep 28 '10 at 21:00

I'd consider using public key auth and the "forced command" functionality therein. In each user's ~/.ssh/authorized_keys file, do something like this:

command="/path/to/application" ssh-rsa <rest_of_users_public_key>

If you set this and turn off password auth (a very good practice anyway), it will ensure that the user will only ever be able to execute the specified application. If you are very confident that there are no means of users executing shell commands through this app, then a chroot jail may not be necessary, but that really needs to be left for you to determine.

share|improve this answer
I like this suggestion, but unfortunately it seems unlikely that my users will be willing/able (technically speaking) to install and manage public ssh keys without significant assistance &ndash; which, honestly, I don't have time to provide. I was planning to provide a low-security login to several different users, then have an app-specific login inside the app itself. Is this a terrible plan? – syrion Sep 28 '10 at 19:33
This comment is not correct. The authorized_keys options should be before the key content. See "AUTHORIZED_KEYS FILE FORMAT" in for more clarification. – Bo Jeanes Nov 28 '12 at 6:39
@bjeanes - good catch. I've updated my answer. Keep in mind that anyone can edit either questions or answers on Serverfault, so instead of downvoting, you could have just fixed my answer. Regardless, it's fixed now. – EEAA Nov 28 '12 at 14:55
A good point. Upon re-reading my comment it seemed a bit harsh — that wasn't my intention. Thanks for fixing! – Bo Jeanes Nov 29 '12 at 15:25
@bjeanes right on! There are definitely times when an answer is so horribly wrong that no one wants to bother fixing it. In cases of a slight syntax error or other small issue, I feel it's typically best to just fix it, as it was likely (as in this case) just an oversight. – EEAA Nov 29 '12 at 15:27

Your Answer


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.