How can I encrypt my bash shell script on Linux server The shell script contain credentials of other servers for remote access. The problem is I do not want others with same level of access to view the shell script, modify it or get credentials. Is there any way to encrypt my shell script? My Initial research let me into Shell Encryption Utility known as SHC - Shell script Compiler.But tons of information is available on this utility that it can be circumvented what other choices do I have?
You could try to encrypt the script using standard methods and decode it on the fly by giving the secret key either directly or through a process. But, this would only help against attackers which have no permissions to modify any of your data or the programs you call, which especially means that they have neither root permission nor the same uid as you. And in this case a simple
chmod go-rwx should already be enough protection.
So against users which have the same or even higher rights as you there is no protection.
But tons of information is available on this utility that it can be circumvented what other choices do I have?
At the end of the day, all of this doesn't make any sense. The computer needs to execute it, therefore at some point in time all of the sensitive information will be somewhere in memory. With current day technology there is no way around it. Anything else is just obfuscation, which may make you feel secure, but probably doesn't meet your expectations.
What probably makes the most sense is to put credentials and other sensitive information into a file and make sure that the file can only be read by the script (i.e. the user executing the script). There are plenty of options to secure files on an operating system level (file permissions, user/groups, SELinux, etc.), which are probably good enough in most cases.