Thursday, 28 March 2019

PGP Commands


Public key (to lock/encrypt the message) and a Private key (to unlock/decrypt the message).

You need to send the public key to all your users so that they can encrypt sensitive messages that they want to send it to you.

 Once you receive an encrypted message, you need to use your private key to decrypt it.


  • Command to generate the key pair. 
             pgp --gen-key "Vijaya User" --key-type RSA --bits 2048 --passphrase "Pass Phrase"
             
            script -q -c "gpg --gen-key" /dev/null
  • Command to list keys. 
            pgp --list-keys
  • export the key using following command.
           pgp --export  $input
           
          input = User Key = "Vijaya User" (from above pgp  generation key)
          input  = Key ID  = This will get generated while creating the key.
  • import pgp key
          pgp  -- import " file_name.asc"

          Reference :  https://linuxaria.com/howto/how-to-easily-encrypt-a-file-with-gpg-on-linux
  • Sample gpg command to decrypt a file :
           gpg --batch --output OUT_PUT_FILE_NAME  --passphrase-fd 0        ENCRYPTED_FILE_NAME.pgp  < pwd.txt

         pwd.txt will have the passphrase.
     
         GPG allows you to bypass prompts with the --batch flag, so we can add that in to our command

        --passphrase-fd 0 tells GnuPG to retrieve the passphrase from input into the current shel

Sample Script to Decrypt:

cat $PassPhrase | gpg --output $OutputFileName --batch --yes --passphrase-fd 0 $SourceFilePath


Sample Script to Enecrypt:

gpg --batch --yes --trust-model always -r $PublicKeyUser -o $OutFilePath -e $SourceFilePath


No comments:

Post a Comment

ERP - GL - Chart Of Accounts

Segments in General Ledger   Segments  are dimensions used to represent an account in a financial system. A company can have anywhere from...