APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed


Control and protect shell scripts

Shell scripts are simple to create, but if a user has permission to execute the script, they also have permission to read it. There are ways to prevent that:

shc - shell script compiler

Shc is available from Francisco Javier Rosales Garcia and compiles with a simple "make".

It's function really isn't a compiler: instead, it encrypts the shell script, and puts a C wrapper around it that, when run, decrypts the script and calls the requested shell for execution. Therefore, you must have a shebang line (#!/bin/sh or whatever). That also means it isn't limited to shell scripts: you can "compile" a Perl script just as easily.

You can optionally specify an expiration date with a message to display if the program is used after that date, and it also allows passing other arguments to the shell. In its simplest form "shc -f script" will produce "script.x" and "script.x.c"; the "script.x" is your executable and the ".c" is the source code.

In the October 2005 Linux Journal, Nalneesh Guar reports that he was able to break the encryption very easily. The man page seems to agree:


 You can use it if you wish to distribute your scripts
 but don't want them to be easily readable by other people.
 

Note 'easily'. As the old saying goes, locks keep out honest people. In a typical office, this might be all you need to prevent casual observation or modification of scripts, and could be useful for that.

Password protect

If all you want to do is password protect a script, there is a simple way to that:

The script you want to protect is /usr/bin/yourscript

Create a user "runme" and set your script tobe exaeutable only by that user:

# useradd -m runme
# passwd runme 
Enter new UNIX password:
Retype new UNIX password:

# chown runme /usr/bin/yourscript
# chmod 700 /usr/bin/yourscript
 

Create the script "/usr/bin/doit" to contain:

su - runme /usr/bin/yourscript

Make "doit" executable

# chmod 755 /usr/bin/doit
 

An ordinary user can't run or read "yourscript", but when they run "doit", they'll be asked for "runme"'s password. If they enter it correctly. "yourscript" will run.





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

Printer Friendly Version

-> -> Control and Protect shell scripts


1 comment




More Articles by

Find me on Google+

© Tony Lawrence







Tue May 5 06:09:14 2009: 6321   DYFeng

gravatar
It's helpful.thx



------------------------
Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

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











This post tagged: