3

I am aware of the security implications and I understand why usage of apt-key was deprecated. For my use case, I do not care.

I want to run:

$ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382

without seeing any warnings. Yet I see:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.KVaQ390iTM/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 /dev/null
gpg: "/dev/null" not a key ID: skipping
gpg: key CC116F55AA7F2382: "Icinga GmbH (Build server) <info@icinga.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

How to force no output for stdout and warnings? I only want to see output of an actual error is happening. (I am aware that the script is running on a system that already knows the key, as I have ran it before.)


I tried:

  • apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 > /dev/null
  • apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 2>&1 > /dev/null
  • apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 2>&1 /dev/null
k0pernikus
  • 6,336

1 Answers1

5

As long as you understand the implication of using deprectated features.

Going through the source code of apt, it seems you can use the APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE environment variable to disable warnings by giving it any value.

$ export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
$ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382
Executing: /tmp/apt-key-gpghome.Co1Q1TlRAY/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382
gpg: key CC116F55AA7F2382: "Icinga GmbH (Build server) <info@icinga.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1 

If you also want to remove the info message, you can pass the -q flag to hide the lines starting with gpg:.

$ apt-key adv -q --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382
Executing: /tmp/apt-key-gpghome.45ExV1NXXg/gpg.1.sh -q --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382

To completely silence it, redirect output to /dev/null

$ apt-key adv -q --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F2382 > /dev/null

Errors will still show up as you requested (removed a character from the key form the command):

$ apt-key adv -q --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CC116F55AA7F232 > /dev/null
gpg: "CC116F55AA7F232" not a key ID: skipping
Dan
  • 14,180