Encryption using Vi (X option). Cannot execute binary file.
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Encryption using Vi (X option). Cannot execute binary file.
Dear Sirs,
I am using encryption of my C-Shell file through Vi editor's X option. After saving the C-Shell file and when I tried to execute C-Shell file, the linux system says "cannot execute binary file". I have already made necessary permissions and executable using
chmod u+x filename
for the C-Shell commands file.
Kindly help me to solve this problem. Is there any other way of encrypting a csh file?. If so, kindly let me know.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Well, if you encrypt your csh file, then first symbols are not #! - and so you have problems executing it.
What effect do you want to achieve? To make script unreadable? To make script unexecutable without password? How strong security do you want?
Generally, write a script that will decrypt and run its own tail after some comment, and prepend it to every encrypted script. But security will not be high.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
You still do not have first line with #! and then valid interpreter name.
About what you want: first, if it is executable without password it is in most cases readable without password also (except for cases with powerful compilers+obfuscators, when you can get something in assembler). Also if you do not want to complicate things too much, you have to decrypt file somewhere, and in that case root can find that moment of time and read the scripts. You can go to http://www.datsi.fi.upm.es/~frosal/sources/ and take shc - shellscript compiler which does approximately what you want. Or you can modify it to request password from keyboard which will make it not so vulnerable.
First: vim != vi
There are those who think the two are synonymous since vim comes installed in most distros. They aren't. Vim is "vi-improved". Vi (and ex) are intended to be very short and sweet and small (and fast). Vim is also intended to be small and fast (compared to other editors), but it has many things vi doesn't. The reason I say this is twofold:
Any newbies reading might become confused. That misconception will keep spreading.
Vi and ex are pretty much guaranteed to be available on every system (even the really stripped down, minimal ones). One day, sooner or later, you will find yourself trying to debug a problem on such a computer. You should know the abilities/limitations of vi.
This isn't a slam on vim or on vi. It is just a simple statement that will better the understanding of unixes among all of us.
Second: If you encrypt a file, you need to decrypt it to use it!
Linux does many things but it doesn't automatically decrypt shell scripts encrypted in vim. What you need is to write a shell script wrapper. This wrapper copies an encrypted wrapper. Then it will decrypt that file. To do this, you probably need to invoke vim as `ex' and you can use it as a script. The encryption should then be turned off (in the ex script). Then, the C-sh file should be executed. Afterward, it should be deleted.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.