Sometimes we program a script in Bash and we want the code of this to be NOT visible, that is, not to be plain text. When we talk about hiding code the correct term is obfuscate, in my case I wanted to obfuscate the code a script that I did some time ago, the utility I found for this is called: shc
shc It allows us to obfuscate code, here are the steps to use it:
1. First we must download it
2. Once we have downloaded it, we right click on the compressed file and select the option that says «Extract here" or something similar. This will make us see a folder called shc-3.8.9, here I show you a screenshot of its content
3. OK, let's say the folder is at /home/usuario/Downloads/shc-3.8.9 Well, we open a terminal and go to that route (cd "/home/usuario/Downloads/shc-3.8.9"), and the installation begins here.
4. In the terminal being located (as I already told you) in the folder shc-3.8.9, in order to install this application we need to make a symbolic link of the file shc-3.8.9.c a shc.c so we execute the following:
ln -s shc-3.8.9.c shc.c
4. Once the link is made, we execute make install with root permissions (we will use sudo):
sudo make install
4. It will ask us for our password and it will wait a moment, it will be waiting for us to press the key [AND] and press [enter], that is, that we confirm that we do want to install the software. Once this is done it will install without problems. I leave you a screenshot of the entire preparation and installation process:
sudo make installes NECESSARY have the packages installed: gcc y make
5. Done, this is it for the installation 😀
When we have it installed, we just need to learn how to use it. Suppose we have a script in our home called script.sh and that its content is as follows:
echo "Script de prueba para DesdeLinux.net"
When executing this script it will obviously show us the message in the terminal: «Test script for FromLinux.net" or not? … But, now we are going to obfuscate that code.
In a terminal we put the following and press [enter]:
shc -v -f $HOME/script.sh
And bingo !! ready 😀
This created us two new files together with our script, now we have script.sh.x y script.sh.xc
script.sh.x - » This is our obfuscated bash script, this when we execute it will do exactly the same as the first one we created, the difference between these is that the first one if we opened it with a text editor (nano, kate, gedit, etc) we could see clearly its content, while if we open to script.sh.x we will clearly see that we do not see anything ... LOL !!!, that is, the code is 'encrypted' 🙂
script.sh.xc - » This is our script but in C language ... we can delete this without worry because we don't really need it, well, at least I wouldn't need it at all 🙂
There's not much else to add actually on the technical side, just clarify that as far as I know with this (hiding or obfuscating bash script code) it is not violating licenses or something like that. I clarify this because a few months ago on Facebook when I mentioned that I had learned to obfuscate bash code, some users alerted me that this was violating licenses or something like that ... well, as far as I understand, licenses are not violated with this 😉
Nothing more to add, any doubt or question, complaint or suggestion let me know.