Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a shell script to be executable but not readable

I created a script which I want other users on our shared system to execute but not read. I set the permissions as executable for all but revoked the R/W rights.

---x--x--x 1 dilletante staff 0 2013-04-02 11:42 expect.sh

However the script Fails to execute...The reason is simple.. The interpreter also needs to read the script

I want a workaround if any..Can I embed it into some compiled language..Would that work? If yes, could you point to the resources where I can learn how to do so..

like image 951
Dilletante Avatar asked Jan 13 '23 18:01

Dilletante


1 Answers

The shell has to be able to read a script to execute it. You are asking for the impossible if it is a script.

You can certainly use 111 permission on an executable program (as produced by the ld command, typically invoked by the compiler of your chosen compiled implementation language). The owner can always change the permission to read the program if they want to, but it is more conventional to use 511 than 111 permission.

There are often compilers for a specific script language that will generate a C program equivalent to the script:

  • Compilers for shell scripts.
  • How to compile a Linux shell script as a binary.
  • Compiling shell scripts.
  • shc — shell script compiler.

Etc.

like image 174
Jonathan Leffler Avatar answered Jan 16 '23 21:01

Jonathan Leffler