what command can be used to encrypt / decrypt files from the command line?
ss you take some security measures to protect your environment and encrypt your data. Linux offers some encryption methods and there are some tools which tin can help you to encrypt your data. Encryption is important when you need to communicate sensitive information with your partners.
What is nada
Cipher is an Ash module that makes it piece of cake to perform aes-256-cbc encryption for files and directories. The ash-shell/nada is licensed under the MIT License.
To install cipher, you lot have to install Ash before. Afterwards you have installed it, you can run either one of these ii commands depending on your git clone preference:
ash apm:install https://github.com/ash-shell/cipher.git or
ash apm:install git@github.com:ash-beat out/goose egg.git one) Encrypt files and directories
With cipher, to encrypt data we utilise the commandnil:e followed by the name/location of the file or the directory. You will be asked to enter the password for the encryption
a. Encrypt files
Let's consider that we have a file with the content below:
# cat file file encrypting with linux cipher tool To encrypt a file, nosotros use the control below
ash aught:east /root/file << nix >>: Enter encryption password: << nil >>: Confirm encryption password: << cipher >>: File encrypted at /root/file.enc From my side, I accept noticed that when I encrypt a file, the original file is not present but only the encrypted file is nowadays. You lot tin can verify as below
# ls -l /root/ total xx -rw-r--r--. 1 root root ninety Jun 25 xix:56 file.enc drwxr-xr-x. ii root root 19 Jun 25 xviii:19 folder You tin come across that we only have the encrypted file name file.enc.The operation automatically adds encextension to the encrypted filename.
We can bank check the content of the encrypted file with the cat control
# cat /root/file.enc U2FsdGVkX19T+dDYuraqLzjsgrazvDTAi0opyeMbfZIuTFRPDsQg/ZXlMHD2Zc+A half-dozen+i3iW3rPgl+NUjpanJkFA== Y'all can that the content is not readable by humans.
b. Encrypt folder
Let's consider the folder beneath
# ls -ld /root/folder drwxr-xr-ten. 2 root root 19 Jun 25 18:19 /root/folder To encrypt the folder, use the command below
# ash cipher:e folder/ << cipher >>: Enter encryption countersign: << cipher >>: Confirm encryption countersign: << cipher >>: Directory encrypted at binder.tar.gz.enc You can meet that the encrypted folder has been compressed. At present let'south check the original folder
# ls -l /root total 24 -rw-r--r--. 1 root root xc Jun 25 19:56 file.enc -rw-r--r--. 1 root root 285 Jun 25 twenty:17 binder.tar.gz.enc Nosotros can observe that the original folder is non present. The encrypted folder has the extension of a compressed file but to run into its content, nosotros use the command cat as below
# cat /root/folder.tar.gz.enc U2FsdGVkX18WP0Lci6rkCfCruUA2P4UmzaOVzGdD1rt824CfNB8KthA0zLOZZDUl xroF8q7tTrxR3RJrJesZcC08fzMZ5JtUnNAM7aIg+bljPFfep2HyP2XK1nRFk5rr GTjUhd3ue5KCxUUaGAypLZHvA1LixX4FUFRV68u8G5VFPtaHSqc50E/qhUHClAKj UlVWCvBtHDkD/DDcw1xjqhQKml5wNMK4N7f5dmaSFuXYBmSrQWcgW00i9URxX6jn 7eRawFYP+zbsl30QCWGrxw== We can endeavor to check the content of the compressed file with the tar command.
# tar -t /root/binder.tar.gz.enc Y'all can see that it is incommunicable to encounter the result, the cursor was held by the prompt. I was forced to use Ctrl-c to take the control of my shell. Nosotros can endeavor to decompress it
# tar -zxvf /root/folder.tar.gz.enc gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now Y'all can come across that we take an error message then the folder is encrypted and we tin can not accept admission to its content.
2) Decrypt files and directories
To decrypt information we utilise the commandcipher:d followed past the name of the file or the directory. You lot volition be asked to enter the password for decryption. It is the aforementioned countersign use for the encryption process.
a. Decrypt files
Now we will decrypt our file with the command below
# ash cipher:d /root/file.enc << cypher >>: Enter decryption password: << zippo >>: File decrypted at /root/file You tin the that the operation is a success. Now allow'due south check the content of our file
# cat /root/file file encrypting with linux naught tool You lot can see the content of our original file
b. Decrypt directories
To decrypt directories, it is exactly the same process as below
# ash aught:d folder.tar.gz.enc << zip >>: Enter decryption password: << goose egg >>: Directory decrypted at folder/ You lot tin see that our folder has been decrypted. At present let'southward cheque the content of our binder
# ls -l folder/ total 4 -rw-r--r--. ane root root 11 Jun 25 21:08 essai Y'all can see that nosotros can now access to our original binder normally.
Conclusion
In one of our earlier article, nosotros accept explained nearly gpg tool, but cypher is a new tool for encryption/decryption information based on countersign which is simple to use. It has uncomplicated control with 2 options for encrypting and decrypting information. The password used for encrypting is the aforementioned for decrypting. I advise y'all to do not use the same passwords for all the file to protect. So, it ways that you will give to your trusted recipient the encrypting password corresponding to each protected file.
andersonwelverepose.blogspot.com
Source: https://linoxide.com/cipher-command-line-tool-encrypt-decrypt-files-directories/
Post a Comment for "what command can be used to encrypt / decrypt files from the command line?"