A customer asked for a way to prevent a certain shell script from execution by SSH - it apparently it is supposed to be run only at the console.
One choice is to examine 'tty'. Something like this, perhaps:
#!/bin/bash case `tty` in /dev/tty*) echo "ok";; /dev/pts/*) echo "No";exit 0; esac echo "Will proceed"
Or perhaps one of the SSH variables can be tested:
#!/bin/bash test -n $SSH_CLIENT && exit 1 echo "Will proceed"
However, that $SSH_CLIENT will not be set if you "su -" to another user after logging in with ssh, so you may need to use the more direct test.
Got something to add? Send me email.
More Articles by Anthony Lawrence © 2013-11-05 Anthony Lawrence