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
UNIX is simple. It just takes a genius to understand its simplicity. (Dennis Ritchie)
Printer Friendly Version
Restrict script to console use Copyright © November 2013 Tony Lawrence
Have you tried Searching this site?
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version