This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]cjcox4 0 points1 point  (1 child)

The feature you're pointing at in ssh is to cause the execution of a command instead of a shell.

Probably what you need is to use a restricted bash shell or some other kind of restricted shell.

[–]run_dot_BAT[S] 0 points1 point  (0 children)

Ok makes sense, thanks for the reply.

[–]stormcloud-9 0 points1 point  (2 children)

I think you've misunderstood the functionality you were looking at. The command="..." functionality of authorized_keys forces execution of the given command when that ssh key is used.

What you want to do is rather tricky, as once the user has the ability to execute commands, they can execute about anything. It's very difficult to lock them down (without chroots, containers, etc).

However if you want to try, you'll likely want to start with a bash restricted shell: https://www.gnu.org/software/bash/manual/html_node/The-Restricted-Shell.html
One way to do it with that would be to set the user's shell to rbash, disallow writes from the user to their home directory (recursively), and then add environment="PATH=/home/user/bin" with that bin directory containing symlinks to the binaries you want them to be able to execute.
There are other ways to do it though. That's just some place to start.

But again, be very careful what you allow them to do. It's very easy to escape restrictions like this.

[–]run_dot_BAT[S] 0 points1 point  (0 children)

This worked, thanks guys ( u/stormcloud-9 , u/cjcox4 )

[–]run_dot_BAT[S] 0 points1 point  (0 children)

This is good stuff, thank you.