Ssh commands restrict python usage

I am using a python script to restrict the use of commands with an argument command

in a file authorized_keys

.

command :

ssh host-name bash --login -c 'exec $0 "$@"' mkdir -p hello

      

My script takes the necessary steps to restrict commands. After filtering, the python script executes sys.exit(1)

for error and sys.exit(0)

for success. After the return value, the above ssh command will fail at the end. Is there something else I need to send from the python script to the SSH daemon?

+3


source to share


2 answers


The modifier command

in is authorized_keys

not used (only) to test the users command, but this command is executed instead of the command supplied by the user. This means that calling sys.exit(0)

from there prevents the user supplied command from being executed.



In this script, after checking this command, you need to run it too!

+2


source


I think I changed it to

ssh host-name bash --login -c 'exec $0 "$@" && mkdir -p hello'

      



must do the trick, otherwise bash will think that only one part in single quotes is the command to execute.

If the second part must be carried out even if the first part fails, replace &&

with;

+1


source







All Articles