Restrict script to console use

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.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Restrict script to console use



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Anthony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

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





The psychological profiling [of a programmer] is mostly the ability to shift levels of abstraction, from low level to high level. To see something in the small and to see something in the large. (Donald Knuth)





This post tagged: