Easy Script To Get And Install PPA GPG Keys

If you use Ubuntu then it’s possible you’ll enable a PPA or two, to install software not in the standard Ubuntu Repositories.

This is a fairly simple process, but there’s a little fiddly bit of work to install the GPG key that goes along with each PPA. If you’re the kind of person that plays around with a lot of PPAs, or uses PPAs on a lot of machines then you’ll probably find yourself doing the GPG key dance a lot.

All round top-man Dominic Evans has crafted a neat little script which automates this process.

His script will not enable the PPAs, but for any PPA already enabled on your system it will go and get the necessary key and install it. If you have lots of PPAs enabled then this is a great way to do all the keys in one hit.

Here’s what happens when you have added a PPA to your Ubuntu sources list, but haven’t done the GPG key dance:-

alan@hactar:~$ sudo apt-get update
[sudo] password for alan:
Hit http://archive.canonical.com jaunty Release.gpg
Ign http://archive.canonical.com jaunty/partner Translation-en_GB
Get: 1 http://ppa.launchpad.net jaunty Release.gpg [307B]

snip

Get: 31 https://private-ppa.launchpad.net jaunty/main Sources [1543B]
Fetched 388kB in 3s (121kB/s)
Reading package lists... Done
W: GPG error: http://ppa.launchpad.net jaunty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5A9BF3BB4E5E17B5
W: GPG error: http://ppa.launchpad.net jaunty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B22AB97AF1CDFA9
W: You may want to run apt-get update to correct these problems

Similarly if you use Update Manager then you’ll get a dialog box titled “An error occurred. The following details are provided:” followed by:-

W: GPG error: http://ppa.launchpad.net jaunty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5A9BF3BB4E5E17B5
W: GPG error: http://ppa.launchpad.net jaunty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B22AB97AF1CDFA9

Of course the number of these, and the keys that you will see displayed will be different depending upon which PPAs you have enabled. Whilst they are only warnings, they’re annoying enough for most people to want them to go away.

To fix this quickly and easily, just grab the script and save it somewhere like /usr/local/bin or (preferably for me) ~/bin (that’s /home/alan/bin on my system). Finally make it executable by right clicking the file in nautilus and go to properties, then select the Permissions tab and enable ‘Allow executing file as a program’. If you like the terminal then you can use the chmod command to do that bit.

Whenever you add a PPA simply run the script in a terminal. Here’s what happens when you run Dominic’s funky script.

alan@hactar:~$ launchpad-update
Grabbing key 4E5E17B5 for archive ppa by ~chromium-daily
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg
 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com 4E5E17B5
gpg: requesting key 4E5E17B5 from hkp server keyserver.ubuntu.com
gpg: key 4E5E17B5: public key "Launchpad PPA for chromium-daily" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
Grabbing key AF1CDFA9 for archive x-updates by ~ubuntu-x-swat
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg
 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com AF1CDFA9
gpg: requesting key AF1CDFA9 from hkp server keyserver.ubuntu.com
gpg: key AF1CDFA9: public key "Launchpad PPA for Ubuntu-X" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
Already have key 3E731F79 for archive ppa by ~siretart
DONE

That’s it. Now when I update…

alan@hactar:~$ sudo apt-get update
Hit http://archive.canonical.com jaunty Release.gpg
Ign http://archive.canonical.com jaunty/partner Translation-en_GB

..snip..

Hit https://private-ppa.launchpad.net jaunty/main Sources
Fetched 617B in 2s (240B/s)
Reading package lists... Done
alan@hactar:~$

No warnings! Lovely. Big hugs for Dominic.

I understand that for Ubuntu Karmic (9.10) this script may become redundant as other changes come in, but for now, and for releases before 9.10 this is awesome!

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
This entry was posted in Advocacy, Linux, Ubuntu. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

31 Comments

  1. Jack W
    Posted June 24, 2009 at 8:57 am | Permalink

    this worked for me:

    for i in `sudo aptitude update 2>&1 | grep NO_PUBKEY | awk '{print $NF;}'`; do sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $i; done

  2. Posted July 8, 2009 at 2:57 pm | Permalink

    Thanks! It was just what I needed :)

      More from author
  3. Thanks
    Posted July 9, 2009 at 5:31 am | Permalink

    Thank you very much lol

  4. nivosh
    Posted July 15, 2009 at 9:18 am | Permalink

    somehow the script wont run:
    nivosh-desktop scripts # launchpad-update
    bash: launchpad-update: command not found

    • Posted July 17, 2009 at 2:31 pm | Permalink

      Did you make sure you changed the acls? i.e

      myprompt> chmod +x launchpade-update

      otherwise it won’t run:

      myprompt> ./launchpade-update

        More from author
    • silvernode
      Posted September 9, 2009 at 12:29 pm | Permalink

      @nivosh open terminal and navigate to the directory with the script. Then type the following commands:

      chmod +x launchpad-update

      then

      ./launchpad-update

      if you made it an executable before and you got that error you mentioned, it’s because you didn’t put ./ before the filename.

  5. Dom
    Posted July 15, 2009 at 1:16 pm | Permalink

    hey what happened to the other comments on this post? :)

    anyhow just a quick fyi
    https://edge.launchpad.net/ubuntu/+source/software-properties/0.75/+changelog

    karmic now has ‘sudo add-apt-repository ppa:oldman’ which adds the sources.list entries and grabs the gpg keys for you

    • Posted July 15, 2009 at 1:48 pm | Permalink

      Well, funny you should ask. I migrated from Drupal to WordPress, and whilst that all went fine, and I have the comments imported into the database (all 963 of them), wordpress barfs when I go to the edit comments page. Not yet figured out how to resolve that. Might be easier to just modify the database and and set all comments to moderated. Suggestions welcome.

        More from author
    • Posted July 15, 2009 at 2:27 pm | Permalink

      mysql> update wpblog.wp_comments set comment_approved = ’1′ where comment_approved = ’0′;
      Query OK, 963 rows affected (0.14 sec)
      Rows matched: 963 Changed: 963 Warnings: 0

      Hurrah!

        More from author
  6. Michael Stelly
    Posted July 16, 2009 at 6:31 am | Permalink

    @nivosh I used the drag/drop method noted by Vadim because I encountered the same issue as you. That worked for me.

  7. Posted August 21, 2009 at 6:24 pm | Permalink

    Thanks for the script, even though i have now changed over to Linux Mint because of Ubuntu Jaunty’s flash issues and difficulty in playing .swf files. Gloria plays media a lot better, you will have to concede that. Besides, it’s dumbed down enough for me, you benevolent eggheads! (no sarcasm, only respect, intended)

      More from author
  8. Tim
    Posted September 8, 2009 at 5:22 pm | Permalink

    Absolutely wonderful. Solved my nagging problem with a PPA that I couldn’t find a key for.

  9. Grant Jackson
    Posted September 14, 2009 at 11:22 pm | Permalink

    I am using karmic in alpha form, and it just imported 2 keys for me no problem.

    Lets hope it keeps working through the beta and final release stages.

  10. Posted November 6, 2009 at 9:35 pm | Permalink

    Here you can find more than one script to add only missing gpg key or all gpg key: http://www.sourceslist.eu/guide/aggiungere-le-chiavi-gpg/

      More from author
  11. David Armour
    Posted November 21, 2009 at 8:34 pm | Permalink

    Thanks for the script. Unfortunately, I’m still getting the following errors at the end of the process:

    Err http://ppa.launchpad.net jaunty/main Packages 404 Not Found
    Err http://ppa.launchpad.net jaunty/main Packages 404 Not Found
    Fetched 616B in 2s (221B/s)
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jaunty/Release Unable to find expected entry free/binary-i386/Packages in Meta-index file (malformed Release file?)
    W: Failed to fetch http://ppa.launchpad.net/psyke83/ubuntu/dists/jaunty/main/binary-i386/Packages 404 Not Found
    W: Failed to fetch http://ppa.launchpad.net/pascal-devuyst/printingbuginfo/ubuntu/dists/jaunty/main/binary-i386/Packages 404 Not Found
    E: Some index files failed to download, they have been ignored, or old ones used instead.

    A couple of questions:
    I understand that “E” = error, but what does “W” mean?
    How can I get rid of the “Failed to fetch” errors?

    Any help at all greatly appreciated. TIA.

  12. nurseto
    Posted December 28, 2009 at 12:26 am | Permalink

    thankyou,,, this really works!
    i love karmic stuff when win7 makes me bored.

  13. thiyagi
    Posted October 16, 2010 at 12:04 am | Permalink

    It really worked, thanks …

  14. Anonymous
    Posted June 5, 2009 at 8:12 pm | Permalink

    Do I get a different result if I just copy the key in a file and double-click that file?

  15. Posted June 18, 2009 at 3:08 pm | Permalink

    It asks for your password via terminal. So open a terminal window, drag the file in, press enter and you’ll be good to go.

    Might need to right-click on it first and set it to be executable via properties->permissions.

      More from author
  16. Alan Pope
    Posted June 5, 2009 at 8:48 pm | Permalink

    No, should be the same.

  17. Posted June 5, 2009 at 11:10 pm | Permalink

    One of the problems that I was talking with a few guys at UDS about was adding keys automatically without actually checking what they hell it’ll verify, this script is still too hard to use for the average person, but could you imagine such an automated thing on the Ubuntu desktop allowing none technical users to add any old PPA without the system even asking them to check who or what is in it?

      More from author
  18. Posted June 6, 2009 at 12:28 am | Permalink

    my little contribution to 100 papercuts :)

  19. Posted June 8, 2009 at 11:30 am | Permalink

    ? keyserver.ubuntu.com != ppa.launchpad.net

    the script does presume that you trust your DNS server’s result for keyserver.ubuntu.com, but if you lose trust in your DNS then what can you trust?

  20. HE
    Posted June 7, 2009 at 9:10 am | Permalink

    What you are doing is automatically fetching whatever GPG key is available on the same host you are getting your data from, and then telling your system to trust everything that comes from that host. Please don’t tell people to do something like that, it completly defies the the idea of using GPG to authenticate package data.

    If you don’t care about what you are doing, just set APT::Get::AllowUnauthenticated “true”; in your apt.conf.d.

  21. Anonymous
    Posted June 6, 2009 at 6:42 am | Permalink

    Thanks for this!

    But Ubuntu still absolutely needs an easy way for desktop users to install packages from PPAs. Having to use the terminal (or to copy and paste the gpg key etc.) is way too complex!

  22. Alan Pope
    Posted June 6, 2009 at 9:19 am | Permalink

    Sure! And as I mentioned at the end, there’s a plan to make this a lot easier.

  23. Philip Newborough
    Posted June 6, 2009 at 7:18 am | Permalink

    Adding PPA keys manually is a PITA. This script is awesome, thank you for sharing! :)

  24. Posted June 8, 2009 at 11:31 am | Permalink

    do you know that you have any missing PPA keys? if it just says done that suggests you either a) already have all your keys, or b) you don’t have any PPAs listed in /etc/apt/sources.list or /etc/apt/sources.list.d/*

  25. Anonymous
    Posted June 7, 2009 at 10:22 am | Permalink

    Doesn’t work for me. It just says DONE and no keys are downloaded.

  26. Anonymous
    Posted June 17, 2009 at 11:46 pm | Permalink

    The script as written won’t find any matching deb lines if there is more than one space after “deb”.

    Change the text beginning:
    grep -o “^deb http
    to:
    grep -o “^deb *http

    I.e., insert an asterisk before “http”.

    All that you’re doing is to allow multiple spaces. The script failed on my system after I’d “prettified” the lines in the sources file.

  27. Posted June 9, 2009 at 4:46 pm | Permalink

    On the other hand, there’s a perl script that I made, fairly older (January 2009) than this bash script you mentioned:
    http://ubuntuforums.org/showthread.php?t=1056099

    “I made a perl script that:
    - Can detect and fix any launchpad PPA link from apt .list files
    - Backs up the original source list (e.g. /etc/apt/sources.list as
    /etc/apt/sources.list.backup)
    - Imports GPG keys for the links detected apt .list files”

    Cheers :)

      More from author

2 Trackbacks

  1. By Fastest PPA fixkey method yet « Indlovu on July 3, 2009 at 11:45 pm

    [...] For a more inclusive but slower method of updating keys, you might like this script from Dominic Evans, which was first noted here. [...]

  2. [...] Aqui esta como hizo para implementar ese script, pero tambien, un lector de Ubuntips (Blog ubuntero recomendado) desarrollo el paquete deb para instalar este script mas facil (y no tener que andar toqueteando ni instalando nada), aqui el post en ubuntips blog, y aqui el enlace hacia ese paquete deb para instalar con un par de clicks y quitarse la monserga de las llaves de los ppa. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Additional comments powered by BackType