2

I'm trying to setup an SSH server which, upon an attempted connection with the correct public key, will create a new user account if one does not exist.

On connection I'd like a specific script to run for that user, which upon exiting, would disconnect them.

The point of this is to have a server which will run a specified script for whoever connects, but with their own account for small save-files.

I'm currently running Ubuntu 14.10 with only a CLI.

I'm not particularly worried about security for the machine in-so-much as it will only be used for games, and contains no personal details of my own.

EDIT: While I feel this question would still be useful if answered in its original form, I have found a work-around that suits me for now: Instead of having ssh do all the work of setting up users on the fly, you can set one user to be accessible via ssh, and that user's launch script can be one which manages user accounts, creating them as needed, and then connecting the user to the correct file directory system for their "account".

  • 1
    A few ideas: superuser.com/a/603099/334516 – muru Apr 5 '15 at 7:52
  • "with the correct public key" - about which key are you talking? – guntbert Apr 5 '15 at 9:03
  • @guntbert If you have ever played a rogue-like or such through an ssh client, you usually have to copy the public_key from the server's website (or ftp) and then send a command like: ssh -C -i cbro_key -l crawler crawl.berotato.org where cbro_key is the public_key – Steve McKibbon Apr 5 '15 at 15:43
  • @muru That is quite interesting, and is pretty close to what I'm after. My issue is my lack of understanding of SSH, however, and figuring out how to have users require a public_key (and possibly generate a private_key to pair it with?) without manually creating a new user and then adding the RSA to their account. Oh, and I still would have no clue how to configure which script to auto-start for them, assuming it's being done automatically. – Steve McKibbon Apr 5 '15 at 15:49
1

I have found a work-around that suits me for now: Instead of having ssh do all the work of setting up users on the fly: you can set one user to be accessible via ssh:

edit /etc/ssh/sshd_config adding a line 'AllowUser <username here>'

and that user's launch script can be one which manages user accounts, creating them as needed, and then connecting the user to the correct file directory system for their "account".

To set a script to run for a specific user connecting via SSH:

edit /etc/ssh/sshd_config adding the lines:

Match user username
    ForceCommand /path/to/script

Where the username is the one you would like to force the command on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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