# # Control and Protect shell scripts
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Control and protect shell scripts

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© September 2005 Tony Lawrence

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.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





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

Printer Friendly Version

->
-> Control and Protect shell scripts

1 comment


Inexpensive and informative Apple related e-books:

Sierra: A Take Control Crash Course

Take Control of Preview

Take Control of Upgrading to El Capitan

El Capitan: A Take Control Crash Course

Take Control of iCloud, Fifth Edition





More Articles by © Tony Lawrence







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

gravatar
It's helpful.thx



------------------------


Printer Friendly Version

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





Computer Science is embarrassed by the computer. (Alan Perlis)




Linux posts

Troubleshooting posts


This post tagged:

Linux

Security

Unix



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode