ssh authorized keys – limit ssh session to custom command

If you want a ssh key to be able to run a custom command only and nothing beyond that, then you can use the “command” option in the authorized_keys file of ssh.

 

For example, to limit user to run only top command with a key, you can add the key like this:

 

echo 'command="/usr/bin/top" ssh-rsa ' >>~/.ssh/authorized_keys