All for Joomla All for Webmasters

How to secure your data with encfs and shell Script / Bash Script


My Best Secure Script to Secure Data with Multiple Options

First of all sorry for my weak English….

Today i have write a Shell Script / Bash Script to securing your data. Basically this script is useful when you have some data and you want many type of security on it. Best thing is that with this script you have two options if you want to give manual password to decrypt your data or If you want to auto decrypt your data with this script. Also i have added MAC address security if any one have your hard drive and he have also this script file than in this script if PC MAC Address does not match it will never decrypt your data. So with MAC Security if you have run this script to auto Mount your data than no one have access if they have your hard drive. Other Best thing in this Script is if you want that when you decrypt your data and some of files deleted automatically.  e.g

You have 3 folder in your encrypted folder.

Test1 Test2 and Test3

Case 1

Now if you want that if you enter password “test” than your encrypted data decrypt but no folder deleted.

Case 2

Now if you want that if you enter password “test1” than your encrypted data decrypt and auto delete your Test1 folder after decrypt.

Case 3

Now if you want that if you enter password “test2” than your encrypted data decrypt and auto delete your Test2 folder after decrypt.

Case 4

Now if you want that if you enter password “test3” than your encrypted data decrypt and auto delete your Test3 folder after decrypt.

So you have to installed encfs and than copy my script and save it.

Then create two folder one for encrypted data and other for decrypted data

mkdir /home/net/encrypt-data

mkdir /home/net/decrypt-data

Then give command to using encfs

encfs /home/net/encrypt-data /home/net/decrypt-data

select “p” for pre-configurations

Then type password

retype password

You have done just copy my script code and enjoy

…………………………………………………………………………………………………………………………

#!/bin/bash

# This is some secure program that uses security.
MYVALID_PASS=”test” #this is our password.
MYVALID_PASS1=”test1″
MYVALID_PASS2=”test3″
MYVALID_PASS3=”test4″

# Use MAC Address in variable
fn=$(ifconfig eth1 | grep -o -E ‘([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}’)
# Compare your PC Mac Address
if [ “$fn” == “0c:5e:7f:17:9a:64” ]; then
echo “Mac Address Match”
echo “Please enter the password:”

 

#Read password you enter
read -s PASSWORD

#Case 1

#Compare Password
if [ “$PASSWORD” == “$MYVALID_PASS” ]; then
echo “You have access!”

# echo 12345678 is your encfs password. Auto decrypt your data with this command without password
echo 12345678 | encfs -S /home/net/encrypt-data /home/net/decrypt-data

 

#Case 2
#Compare Password
elif [ “$PASSWORD” == “$MYVALID_PASS1” ]; then
echo “You have access!”

# echo 12345678 is your encfs password. Auto decrypt your data with this command without password
echo 12345678 | encfs -S /home/net/encrypt-data /home/net/decrypt-data

# rm -rf will delete your folder Test1 if you enter password test1
rm -rf /home/net/decrypt-data/Test1

 

#Case 3
#Compare Password

elif [ “$PASSWORD” == “$MYVALID_PASS2” ]; then

echo “You have access!”

# echo 12345678 is your encfs password. Auto decrypt your data with this command without password
echo 12345678 | encfs -S /home/net/encrypt-data /home/net/decrypt-data/

# rm -rf will delete your folder Test2 if you enter password test3
rm -rf /home/net/decrypt-data/Test2

 

#Case 4
#Compare Password

elif [ “$PASSWORD” == “$MYVALID_PASS3” ]; then
echo “You have access!”

# echo 12345678 is your encfs password. Auto decrypt your data with this command without password
echo 12345678 | encfs -S /home/net/encrypt-data /home/net/decrypt-data/

# rm -rf will delete your folder Test3 if you enter password test3
rm -rf /home/net/decrypt-data/Test3

else
echo “ACCESS DENIED!”

fi
fi
………………………………………………………………………………………………………………………………….

Copy Above code and save it to enc.sh and give execute permission.

I have one more script to unmount decrypt data so copy below code and save it as decrpt.sh

………………………………………………………………………………………………….

#!/bin/bash
To unmount your decrypt data
fusermount -u /home/net/decrypt-data/

…………………………………………………………………………………………………..

You have to enter your ether net Name and MAC Address manually in above script. e.g i have eth1 and its MAC address below just use echo command to show your mac address copy it to your script

# Use MAC Address in variable
fn=$(ifconfig eth1 | grep -o -E ‘([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}’)

echo $fn

this echo command show your MAC address. then copy this MAC address to your script like below and remember to change your ether net which you want to use in this script like eht0 eth1 etc
# Compare your PC Mac Address
if [ “$fn” == “0c:5e:7f:17:9a:64” ]; then

Now after this we have to secure our shell script because in script we have our passwords

Download SHC from this website “https://github.com/neurobin/shc”

extract shc-release.zip file and copy shc-release/bin/x32/shc for 32 bit and shc-release/bin/x64/shc for 64 bit OS and copy it to usr/local/bin

To Copy this with command if you have shc-release folder is in HOME

For 32 bit OS

sudo cp -R /home/net/shc-release/bin/x32/shc /usr/local/bin

For 64 bit OS

sudo cp -R /home/net/shc-release/bin/x64/shc /usr/local/bin

Now open terminal and give Command. Here enc.sh is your above code script

shc -f /home/net/enc.sh

shc -f /home/net/decrpt.sh

it will create enc.sh.x, decrpt.sh.x and binary file just copy enc.sh.x, decrpt.sh.x to bin folder and after full check you have to delete enc.sh because it is in plain text and any one see your password writen in this file so must delete after convert it with SHC

sudo cp -R /home/net/enc.sh /usr/local/bin

sudo cp -R /home/net/decrpt.sh /usr/local/bin

Now open terminal and enter command enc.sh.x it will prompt for password give your required password and it will decrypt your data. And after work enter command decrpt.sh.x it will unmount your decrypted data.

Secure Data with encsf and shell script / Bash script

Please if you have any problem or question about this script ask in comments i have to try my best to solve it

Thanks

Malik Awan

 


Like it? Share with your friends!

6 SHARES
0
6 SHARES, 0 points

How to secure your data with encfs and shell Script / Bash Script

log in

Become a part of our community!

reset password

Back to
log in
Choose A Format
Personality quiz
Trivia quiz
Poll
Story
List
Meme
Video
Audio
Image