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 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.
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.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-05-01 Tony Lawrence
Computer Science is embarrassed by the computer. (Alan Perlis)
Tue May 5 06:09:14 2009: 6321 DYFeng
It's helpful.thx
------------------------
Printer Friendly Version
shc - shell script compiler Copyright © September 2005 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