Search code examples
encryptiongnupg

Encrypt file from command line with gpg


I wish to encrypt my file "testfile" with symmetrical encryption. From the posts I read using 'gpg' is the most popular/common way to do so in the Linux world. (I want to ensure Linux users I send it to don't have to install more tools to decrypt the file).

Based on several posts I chose 'gpg' and this should be pretty simple. But I get the error as shown below:

[root@mpserver tmp]# gpg --symmetric --passphrase "**KHns4621vHJG4**" testfile
gpg: problem with the agent: No pinentry
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of `testfile' failed: Operation cancelled
[root@myserver tmp]# gpg --version
gpg (GnuPG) 2.0.22
libgcrypt 1.5.3
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, ?, ?, ELG, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

What is wrong with my command?


Solution

  • GPG by default does not allow passphrases in the command line.

    You should add --batch --yes. Like that:

    gpg --batch --yes --symmetric --passphrase "**KHns4621vHJG4**" testfile