Ssh tips and tricks, part 6

Time for the sixth parth of the ssh guide. This time I’ll dig a bit deeper into using a command in your authorized_keys file. That way you will be able to remotely run a command, about the same way you would like: ssh b10m.example.net uptime, which would return the uptime of the server. If you want to restrict the commands that can be used in the remote command, simply put them into the ~/.ssh/authorized_keys file:
bq. command=”/usr/bin/uptime” ssh-dss AAAAB3NzaC1kc3M…[ rest of key ]…ED8s Comment
If you try to login to the other server now, you only get the output of uptime back:
bq. $ ssh joffie@b10m.example.net
9:24PM up 162 days, 3:45, 5 users, load averages: 0.03, 0.14, 0.12
Make sure that you have got the full command you want to run in the authorized_keys and nothing that could be used by hackers. If you, for example, have a command like command="/usr/bin/vi /tmp/file.txt", the user could exit this vi session with a command like :!/usr/local/bin/bash. Though this example might not seem too “real world”, it shows that you always need to think on what a hacker can do. (In this case starting vi with the -S option would disallow external program calls).
Other interesting features are the use of SSH_ORIGINAL_COMMAND, which is given to the remote environment.