Need to assign gpg decrypted filename to a variable - bash

I'm using below command(non -interactive mode of gpg) to decrypt my file:
gpg --yes --batch --passphrase=Abcdefgh1$ kbc.text.gpg
The file it will decrypt will be kbc.text. Now, in my script I need to assign name of this decrypted file to a variable which I need to use further. For that, I'm using below command:
tmp=gpg --yes --batch --passphrase=Abcdefgh1$ kbc.text.gpg
However, when I run this, I get below error:
script2.sh: line 2: --yes: command not found
Any way to implement this and avoid this error. Any help will be appreciated.

Related

Ansible vault wrapping script with GPG

I was tring to find the most secure way of using ansible vault in a docker env and the option of keeping the password as plain text in a file seems not so good so i saw a post about protecting the plain text file with gpg, now it all works great except that the gpg file is asking for its password randomly and it is on a docker container so it does not help :(
Here is how i set this up:
gpg-wrapper.sh -
#!/bin/sh
VAULT_PW_FILENAME="/base/vaults/vault.gpg"
gpg --quiet --batch --use-agent --decrypt $VAULT_PW_FILENAME
ansible.cfg -
vault_password_file = /base/vaults/gpg-wrapper.sh
encrypted like this:
gpg -c vault #which created the vault.gpg file
Is there another way for it ? a better one? or a way to keep gpg to ask the password once?
Thanks!

How can I decrypt multiple .exe files in a directory using gpg?

When I double click on a file PGP SDA asks for passphrase. I am able to decrypt files with a .gpg extension using this script:
gpg --batch --yes --passphrase 12345 --decrypt-files *.gpg
But when I run the above command with *.exe it gives me unknown suffix error.

Simple way to encrypt and decrypt a backup file in bash

I need to encrypt a backup file gzip.
I performed the following operation.,
tar -Pzcvf $dir/*.xml >/dev/null | gpg --yes --batch --passphrase PaSsW0rD -o "$bpath/$bfile".tar.gz
But it is failing with the following error.,
gpg: processing message failed: Unknown system error
I just need a simple passsord protected backup file. Any other alternative solutions are also welcome.
Thanks in advance
Option 1
Doing it your way :
tar -zcvf your_tar_file_name.tar.gz "$dir"/*.xml && gpg --symmetric --cipher-algo AES256 your_tar_file_name.tar.gz
Note that I do not wish to preserve absolute names, so I have stripped the P option from tar. The default output file in this case is your_tar_file_name.tar.gz.gpg.
To decrypt and get the files back you may do :
gpg -o my_tar_file.tar.gz -d your_tar_file_name.tar.gz.gpg && tar -xzf my_tar_file.tar.gz
This uses a symmetric encryption scheme, ie, we could use the same password to decrypt the file. The above command will ask you to enter the password for encryption and confirm it.
If you wish to do asymmetric encryption using gpg have a look at this tutorial.
Option 2
You may also use aescrypt
Download aescrypt from here
Once installed you may use the straight-forward GUI to encrypt the file.
If you need the command line tool, you could use the aescrypt command like below:
tar zcvf your_tar_file_name.tar.gz "$dir"/*.xml && aescrypt -e -p yourstrongpassword your_tar_file_name.tar.gz
Here e is for encryption and p is for password. The output will usually be stored in your_tar_file_name.tar.gz.aes.
You could decrypt the your_tar_file_name.tar.gz.aes file using
aescrypt -d -p yourstrongpassword your_tar_file_name.tar.gz.aes
Here d is for decryption.

How can I encrypt files in GPG with password under dot

Just wondering, how can I encrypt files with GPG with password under dot?
I have a file called test.txt and I want to encrypt this file into GPG with password, so this is the script I wrote to encrypt the file:
gpg - c test.txt
then it is asking for the Passphrase and I entered abc123. File test.txt.gpg was generated as a result.
Then I tried to decrypt the gpg file by using the following script under dot:
gpg -o testing.txt -d test.txt.gpg
It decrypted the file for me without asking for the password (abc123).
Does anyone know where is going wrong with my encrypt?

How to enter password that an external program asks from batch file

I'm writing a batch file to execute a program and do some requirements. After some steps, it asks me password.
Here is the .bat file I'm executing from command prompt;
C:
cd "C:\PROGRAM FILES (X86)\GNUPT\GPG"
gpg -se -r "Someone <s.s#s.com>" "D:\20130328pcs0CONTAINER0035017310.txt"
So, after this step, that gpg program asks me my password;
Anyone knows how to write password here from batch file ?
From the http://www.gnupg.org/documentation/manpage.en.html, did u try using:
--passphrase-fd n
Read the passphrase from file descriptor n. If you use 0 for n, the
passphrase will be read from stdin. This can only be used if only one
passphrase is supplied. Don't use this option if you can avoid it.
Not sure if something like this would work, set n to 1 to get the passphrase from the sdtout
maybe
gpg -se -r "Someone <s.s#s.com>" "D:\20130328pcs0CONTAINER0035017310.txt --passphrase-fd 1 & echo somePassword"
this makes one independent from the other so maybe it works. Please tell what happens
EDIT:
Mtok solved it with this:
gpg --trust-model always --passphrase some password --yes -se -r "<someone s#s.com>" "D:abc.txt"

Resources