Encrypt a File/Directory in CentOS

First you have to install pinentry-gui
# yum install pinentry-gui

then create a .sh file
]# vi encrypt.sh

#!/bin/bash
echo "Welcome, I am ready to encrypt a file/folder for you"
echo "currently I have a limitation, Place me to thh same folder, where a file to be
encrypted is present"
echo "Enter the Exact File Name with extension"
read file;
gpg -c $file
echo "I have encrypted the file successfully..."
echo "Now I will be removing the original file"
rm -rf $file

save the file
this script will encrypt file and directories

change file permission
]# chmod 755 encrypt.sh

Execute the script
]# ./encrypt.sh

# ./encrypt.sh
Welcome, I am ready to encrypt a file/folder for you
currently I have a limitation, Place me to thh same folder, where a file to be
encrypted is present
Enter the Exact File Name with extension
Boobalan.docx

   ┌─────────────────────────────────────────────────────┐
            │ Enter passphrase                                    │
            │                                                     │
            │                                                     │
            │ Passphrase ________________________________________ │
            │                                                     │
            │       <OK>                             <Cancel>     │
            └─────────────────────────────────────────────────────┘

give the encrypt password twice. then it will encrypt
gpg -c will encrypt your file

gpg -d for decrypt your file

]# gpg -d Boobalan.docx.gpg >Boobalan.docx

give the password then your file was successfully decrypt. 


Post a Comment

0 Comments