ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have written a shell script called install.sh consisting of various commands(around 200 lines). The script works fine.
Now, what I would like to know is that if there is any way by which I can hide the code of the script by using some encryption? If not encryption then, will it make sense to put the entire script in a C program and then compile it to just get a binary file and then execute it in a shell?
Basically, all I want is that my code in the shell script should not be seen? Is it possible to do that?
If you want to hide it you could just set it up so that it can only be read by root then give sudo access to execute it to the users you intend to run it.
You could do C and run the various lines as "system ..." but it seems if you know C well enough it would be best to create a C binary.
Once upon a time there was a company called Lone-Tar that made various little products for Unix one of which I evaluated was to make binaries out of shell scripts. It worked fine but on running tests it didn't operate any more quickly than the original shell script so I suspected it just did the multiple system calls I mentioned above. However it did hide the code so would have worked for the application I'd intended (didn't know about sudo then and not even sure it existed then).
Their web site is www.cactus.com - Just had a look and don't see the product listed and I don't recall what it was called. Perhaps if you phone them they still have it and can give you details.
Thanks for reply and the website. Actually, my script just contains a bunch of Linux system administration commands.And also the root user option that you have sugested would not work because the people who are going to run the script will have the root access so that option is ruled out.
Is there a significant disadvantage is I put all the commands using system("command-name") in the C file? Is there any other way by which I can do this in a C Program?
Only disadvantage of embedding "system" in your C code is that it is slower than a binary needs to be. Binaries are machine code so don't need to be interpreted. Shell scripts do and "system" calls essentially do the same thing as a shell.
That is to say a C program you wrote from scratch using C libraries would normally be much faster than a shell script that had the same purpose. This is one of the reasons Perl is around. It tries to combine the speed of C with the accessibility of shell scripting.
Unfortunately I've never spent much time in C so can't really give you good coding tips for it.
No, i've never needed to hide my code from someone.
Right, and this is the way to follow !
Hiding code is wanted only for wrong reasons, and is doomed anyway.
Anyone wanting to crack it will succeed doing it sooner or later ...
Looks like shc does what he wants. However further google on shc itself indicates it isn't that hard to hack the encryption but for preventing casual view of your shell code it looks like it would do the trick. It sounds like it does pretty much what the product I'd gotten from Cactus previously was doing.
Originally posted by jlliagre Right, and this is the way to follow !
Hiding code is wanted only for wrong reasons, and is doomed anyway.
Anyone wanting to crack it will succeed doing it sooner or later ...
Well, there is not bad intent to hide the code in my case if you believe me. . I have a constraint because if novice user modify my scripts, there is a quite a possibility that they might screw their own systems(since the script does some sysadmin tasks) and that;s the reason I wanted to hide the code in the script.
- These users are so ignorant they're likely to trash their systems ... but you're giving them root privileges?
- And you're worried that they'll read your code (which does some task correctly) and deliberately
hack it, and hack it incorrectly, and so that's why you need to "lock it up"???
Encryption might help.
But it sounds like a written "System Use" policy, together with a solid user training and support program, might be a much better overall solution in the long run.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.