How to encrypt a file in linux (or cygwin)

root's picture

Some of you already know that Windows zip combines several different functionalities:
- compression (like gzip),
- archiving multiple files into one (like tar),
- encryption (like gpg),
- plus some other.

Unix and Unix-like operating systems tend to split them so do not be surprised to have gzip for compression, tar for archiving files into one and gpg to encrypt.

In this article we will write about gpg

You probably are in situation where you need to put a password on a compressed archive and you realize tar or gzip cannot do that.
To the rescue comes gpg. There are other tools and ways to do so but I found gpg the simplest.

So, in order to encrypt an existing file, a compressed archived in our case, you need to do as follows:

To encrypt: $ gpg -o notes.tar.gz.gpg --symmetric archive.tar.gz
To decrypt: $ gpg notes.tar.gz.gpg

Output of such operation (do note that encrypt will prompt you for a password - not seen in the output example because it is hidden by the tool):

flo@cygwin Stuff$ gpg -o notes.tar.gz.gpg --symmetric notes.tar.gz

flo@cygwin Stuff$ ls -la notes.tar.gz*
-rw-rw-r--+ 1 flo Domain Users 304M Aug 21 11:22  notes.tar.gz
-rw-rw-r--+ 1 flo Domain Users 304M Aug 21 11:27  notes.tar.gz.gpg
flo@cygwin Stuff$ rm notes.tar.gz
rm: remove regular file 'notes.tar.gz'? y
flo@cygwin Stuff$ gpg notes.tar.gz.gpg
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
flo@cygwin Stuff$ ls -la notes.tar.gz*
-rw-rw-r--+ 1 flo Domain Users 304M Aug 21 11:28  notes.tar.gz
-rw-rw-r--+ 1 flo Domain Users 304M Aug 21 11:27  notes.tar.gz.gpg

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root