Cipher – Two Simple Commands To Encrypt/Decrypt Files and Directories In Linux Command Line

We have wrote many articles about files and directories encryption and decryption but cipher is one of the easiest way to perform encryption and decryption without any Linux knowledge.

Why we need an encryption?

Encryption is the process of encoding a message or information from plaintext to ciphertext which cannot be read anyone except authorized users. It help us to protect and transfer the confidential information over the network.

What is Cipher?

Cipher is an Ash module that makes it easy to perform aes-256-cbc encryption for files and directories. It’s an another Linux command line utility.

Make sure, you have to install Ash module in order to use Cipher.

Suggested Read :
>: Cryptkeeper – An Easy Way To Encrypt And Decrypt Folder or Directory In Linux
>: GnuPG – An Easy Way To Encrypt/Decrypt Files From Command Line in Linux
>: SiriKali – GUI Front End To Manage ecryptfs, cryfs, gocryptfs, securefs, and encfs Encrypted Folders
>: Gnome Encfs Manager – An Ease way to Create a Encrypted Directory in Linux
>: Steghide – An Easy way to Hide Confidential Data Inside Images and Sound Objects in Linux

What is Ash?

Ash is a modular Bash framework written with ease of use + reusability in mind. Modules are the fundamental building blocks of Ash. They allow you to build out custom CLI’s and libraries that can be used in any other Ash module.

How to Install Ash?

Developer offering a shell script which will take care an installation part. This script will install the Ash utility @ /usr/local/ash.

# curl https://raw.githubusercontent.com/ash-shell/ash/master/install.sh | sh

How to Install Cipher?

After you have Ash installed, just run the following command to install Cipher module.

# ash apm:install https://github.com/ash-shell/cipher.git

How to Encrypt File using Cipher

Let’s create a file name called file1.txt with following contents This is test file for Cipher encryption.

There is no difficult syntax for encryption, just use cipher:e and followed by file path. It’s using the same syntax for folder encryption too.

# more file1.txt
This is test file for Cipher encryption

Run the following command to encrypt the file called file1.txt. It will ask you to enter the password twice to encrypt a file.

# ash cipher:e file1.txt
<< cipher >>: Enter encryption password:
<< cipher >>: Confirm encryption password:
<< cipher >>: File encrypted at file1.txt.enc

Post encryption the original file has been converted as .enc extension.

check whether the encrypted file readable or not without decryption.

# ls -lh
total 4.0K
-rw-------  1 root root   90 Jul  5 15:23 file1.txt.enc

# more file1.txt.enc
U2FsdGVkX18Y6Z7ucv7/+lrOnOXacqdhR33mZYPLqJUehgVowQndrdRjGd27ZIJZ
2PxZjyIb9a+I1Z7CePegcA==

No, its not in readable format.

How to Decrypt File using Cipher

There is no difficult syntax for decryption, just use cipher:d and followed by file path.

# ash cipher:d file1.txt.enc
<< cipher >>: Enter decryption password:
<< cipher >>: File decrypted at file1.txt

It will ask you to enter the password to decrypt the file. This decryption again replace the original file called file1.txt from file1.txt.enc

Now, i can able to read the file.

# more file1.txt
This is test file for Cipher encryption

How to Encrypt Folder using Cipher

It’s using the same command cipher:e for folder encryption too. Let’s imagine, we have a folder called folder2 for this experiment.

# ls -lh
total 4.0K
drwx------  2 root root 4.0K Feb 10 15:47 folder2

Run the following command to encrypt the folder called folder2. It will ask you to enter the password twice to encrypt a folder.

# ash cipher:e folder2/
<< cipher >>: Enter encryption password:
<< cipher >>: Confirm encryption password:
<< cipher >>: Directory encrypted at folder2.tar.gz.enc

Post encryption the original folder has been converted as .tar.gz.enc extension file.

Check whether the encrypted folder can accessible or not without decryption.

# ls -lh
total 4.0K
-rw-------  1 root root  285 Jul  5 15:27 folder2.tar.gz.enc

# cd folder2.tar.gz.enc
-bash: cd: folder2.tar.gz.enc: Not a directory

# more folder2.tar.gz.enc
U2FsdGVkX18YJSwvcZj+3VdrkVizqr8RuXmTLuV16165o6hSJ7y/3I3Hdpy+ewwR
FRlJ//kNv8IK/OwW+Nl3YmJDp3uMQom8otXviw+f6n7rqfi6T7qeYhlLL5rO6v5A
vZTYnGut6tVOv2G4ZloBkj4Cuz2Nv8M7knWk8x6yAzwKEqbCSA0206RfBNvHipi/
CCu7KtC5pciQ+uc05+LT0u58Uw6jvvJhXVq4x8HG66HRwIZBFnqJnw0IZKZT4V9p
kY3sbG92iIs0tjc4g38JaA==

No, its not in accessible format.

How to Decrypt folder using Cipher

Just use cipher:d and followed by folder path to decrypt a folder.

# ash cipher:d folder2.tar.gz.enc
<< cipher >>: Enter decryption password:
<< cipher >>: Directory decrypted at folder2/

It will ask you to enter the password once to decrypt a folder. This decryption again replace the original folder called folder2 from folder2.tar.gz.enc

Now, i can able to access a folder and it’s sub-directory too.

# ls -lh
total 4.0K
drwx------  2 root root 4.0K Jul  5 15:24 folder2

# cd folder2/

# ls -lh 
total 4.0K
-rw------- 1 root root 42 Jul  5 15:25 file2.txt

You may also like...

Close
Please support the site
By clicking any of these buttons you help our site to get better