Ubuntu: Add a key from downloaded file


     RUN curl -s http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh/archive.key | apt-key add -  

This is the statement i am using to download a key and add to it. It works fine. But i want to do it in the following way

     Download the key from url and add it  

I have downloaded it into /usr/local.

     /usr/local/archive.key | apt-key add -  

I tried this. But i am getting the following error

    usr/local/archive.key: 1: usr/local/archive.key: -----BEGIN: not found      usr/local/archive.key: 2: usr/local/archive.key: Syntax error: "(" unexpected      gpg: no valid OpenPGP data found.  

Any ideas to achieve it from downloaded file?

EDIT: What's the wrong in my file | apt-key add - syntax? Will it consider the thing before to pipe as url?


When you type in file | apt-key add - you tell the system to execute the file and feed the output to apt-key.

If you want to feed the content of file to apt-key you should use:

cat file | apt-key add -


As long as you have execute permissions for that file the system will try to execute it. The system reads the few bytes at the beginning of the file (i.e. #!/bin/sh or #!/usr/bin/python or the binary executable header) and tries to figure out how exactly should it execute it. In your case it finds the beginning of the key: -----BEGIN, has no idea how to execute it and gives you somewhat cryptic error message.


It's a syntax error. From Man page

    apt-key [--keyring filename] [command] [arguments...]  

So, It should be

   apt-key add /usr/local/archive.key  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »