HostOnNet Blog

Encrypt files

Looking for Linux Server Admin or WordPress Expert? We can help.

Here are some ways you can encrypt files on a linux system.

GPG

To encrypt a file with gpg, run

gpg --symmetric --cipher-algo AES256 -o FILE_NAME.secure FILE_NAME

You will be asked to enter password.

Example

boby@hon-pc-01:~$ gpg --symmetric --cipher-algo AES256 -o forums.txt.secure ~/work/MY_FILES/forums.txt
boby@hon-pc-01:~$

To decrypt, run

gpg --output FILE_NAME -d FILE_NAME.secure

Example

boby@hon-pc-01:~$ gpg --output forums.txt -d forums.txt.secure
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase
boby@hon-pc-01:~$ 

openssl

To encrypt with openssl, run

openssl enc -aes-256-cbc -in FILE_NAME -out FILE_NAME.secure

Example

boby@hon-pc-01:~$ openssl enc -aes-256-cbc -in ~/work/MY_FILES/forums.txt -out forums.txt.secure
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
boby@hon-pc-01:~$

To decrypt, run

openssl enc -d -aes-256-cbc -in FILE_NAME.secure -out FILE_NAME

Example

root@hon-vpn:~# openssl enc -d -aes-256-cbc -in forums.txt.secure -out forums.txt
enter aes-256-cbc decryption password:
root@hon-vpn:~# 

Posted in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.