GNUPG: Suppress message while deleting public key
Asked Answered
B

4

5

I am using the GNUPG tool for performing encryption/decryption using the command line. While deleting the public key I am giving the following command : gpg2 --quite --yes --delete-key "Solveon DB"

After the command gets executed I get the question Delete this key from the keyring? (y/N)

I dont want this question to be asked. Can you suggest which option to use. I tried specifying the fingerprint but I couldn't figure out the use. 1 hour ago - 4 days left to answer. I had created a C# wrapper class to use the tool but when using delete option it hangs the application as its waiting for answer to the question. Additional Details

Link for commands: I have used the software which I downloaded from this site: http://www.gpg4win.org/

http://www.linuxguide.it/command_line/linux-manpage/do.php?file=gpg

Building answered 19/3, 2012 at 10:23 Comment(0)
D
10

use following

gpg2 --batch --yes --delete-key "Solveon DB"

Please note that it will only work when you want to delete the public key .

Dumas answered 3/6, 2014 at 7:6 Comment(0)
Q
2

You've got a typo in your question (it's --quiet, not --quite) but this won't quiet gpg2 down completely. The option you need in this case is --batch.

To delete a key in batch mode, you'll have to specify it using the fingerprint. You can find the fingerprints for your keys with this command:

$ gpg2 --list-keys --fingerprint
/home/joeschmoe/.gnupg/pubring.gpg
----------------------------------
pub   2048R/3C6033BD 2012-02-15
      Key fingerprint = EA8B 7339 D8AB 608D D9B6  BFA2 797B 679C 3C60 33BD
uid                  Joe Schmoe <[email protected]>
sub   2048R/8C61295F 2012-02-15

The fingerprint gets displayed in 4 character groups for easy reading, but when using it to identify the key to delete, drop the spaces and use just the 40 characters of the fingerprint:

$ gpg2 --batch --delete-key EA8B7339D8AB608DD9B6BFA2797B679C3C6033BD
Quietus answered 20/3, 2012 at 20:5 Comment(1)
gpg: can't do this in batch mode without "--yes"Ruisdael
B
1

Here is another solution to delete all secret keys and then "user123" keys, expired and non-expired.

First script is looking for fingerprint's and make a solid numeric string form their symbols (z.B., ADFG1HJH3JHG5HGTY6KJYY6KJHKK535JNNN).

gpg --list-keys --fingerprint | grep fingerprint | cut -c 25-74 | sed 's/ //g'

Other code is clear for understanding.

#!/bin/bash

function myfunc()
{

local SKEY=$(gpg --list-keys --fingerprint | grep fingerprint | cut -c 25-74 | sed 's/ //g')

echo "$SKEY"

}

SKEY1=$(myfunc)

#echo $SKEY1

gpg --batch --fingerprint --yes --delete-secret-key $SKEY1 <<EOF 

$SKEY1 

EOF

#rm -rf ex.txt

gpg --batch --yes --delete-key "user123"
Blessington answered 15/8, 2019 at 13:27 Comment(1)
Do not pay attention to string: rm -rf ex.txt It should not be there:)Blessington
H
1

After puzzling over this myself, I found you can use CMD to delete both public and private keys. Here's the code I used for this:

gpg --batch --yes --delete-key [keyID]
gpg --batch --yes --delete-secret-key [ClientKeyID]

Where the text+square brackets is replaced by the 40 digit key fingerprint, and the lines apply to public and private keys respectively. I call a batch file from within powershell to achieve this and it works perfectly.

Hashum answered 13/1, 2021 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.