Take a look at the command
-option for SSH's authorized_keys-file. This way, you can force a command on specific users accessing your machine depending on their SSH key.
Imagine a user named "git" on your server. This user has the following authorized_keys-file as an example:
command="/path/to/script user1",no-port-forwarding,no-X11-forwarding,no-pty ssh-rsa [public key of user1]
command="/path/to/script user2",no-port-forwarding,no-X11-forwarding,no-pty ssh-rsa [public key of user2]
So when user1 runs ssh git@yourserver.com "/execute/command --with --parameter"
, /path/to/script
is called (as git user). This script can access the original command (/execute/command --with --parameter
) in the environment variable $SSH_ORIGINAL_COMMAND (dive into the SSH documentation for more details).
This way, it is only a matter of getting the right lines into the authorized_keys-file (you could dynamically build the file from the keys stored in your database).
From there you could write your own shell or do whatever you want with the original command.
This is basically how gitolite and gitosis manage git repository permissions (Github uses one of these I think).
Hope this helps a bit - kind regards!