GPG (GNU Privacy Guard) - Encrypt a file using GPG (-c --symmetric)

by
Jeremy Canfield |
Updated: August 14 2021
| GPG (GNU Privacy Guard) articles
Let's say you want to encrypt /tmp/foo.txt using GPG. The gpg command with the -c (create) or --symmetric flag can be used to encrypt foo.txt. You will be prompted to provide a passphrase.
gpg -c /tmp/foo.txt
Now there should be two files, the original file and the GPG encrypted file.
~]# ll /tmp
-rw-r--r-- 1 root root 12 Aug 14 13:38 foo.txt
-rw-r--r-- 1 root root 89 Aug 14 13:39 foo.txt.gpg
Output file name
By default, the GPG encrypted file will be the original file name with the .gpg extension. The --output option can be used to define the name of the GPG encrypted file. In this example, the GPG encrypted file will be /tmp/bar.txt.gpg.
gpg -c --output /tmp/bar.txt.gpg /tmp/foo.txt
Cipher Algorithm
By default, cipher AES-128 will be used when encrypting a file. The --cipher-algo option can be used to use some other algorithm.
gpg -c --cipher-algo AES-256 /tmp/foo.txt
Did you find this article helpful?
If so, consider buying me a coffee over at