wget throws a 'missing url' when trying to install a repository signature key

I am installing INetSim on Ubuntu and when running this command to install the signature key for the program:

sudo wget -O - http://www.inetsim.org/inetsim.org-archive-signing-key.asc | apt-key add -

I get the message:

wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

Why am I getting this error?

enter image description here


The wget command in your question text is not matching the command in your screenshot. Here is the command in your screenshot:

sudo wget -O http://www.inetsim.org/inetsim.org-archive-signing-key.asc | apt-key add -

Here is the command in your example text; also check the command used in the official INetSim installation instructions:

sudo wget -O - http://www.inetsim.org/inetsim.org-archive-signing-key.asc | apt-key add -

Note the subtle difference? The one that is failing is missing the - between sudo wget -O and the URL that follows it. Try it with the - and it should work fine.

Just so you understand what was—or wasn’t—happening, the -O (--output-document flag needed that - to tell wget to stream the contents of that URL to standard output. If you just ran the command like this:

wget http://www.inetsim.org/inetsim.org-archive-signing-key.asc

All wget would do is save that file locally on your system to a file named inetsim.org-archive-signing-key.asc. But setting -O - and then having that pipe (|) to | apt-key add - the command is basically saying, stream the contents of that file to standard put, then pipe that output to apt-key add so the key contents can be added to your apt repository list.

Also, your screenshot shows the additional error:

ERROR: This command can only be used by root.

That is directly related to the lack of the dash in your command; it causes everything else to fail as well.

If the command’s pipe(s) are broken the whole command fails and it will never get to the point where you are prompted to enter the sudo password. But the rest of the command is still being parsed anyway.

So even thought the full command fails it’s still trying to run apt-key. And since the remaining part of the one-line command is basically detached from the rest of the previous sudo invoked command—which never was ever invoked as sudo due to the error—it attempts to run apt-key as a normal user it then says:

ERROR: This command can only be used by root.

Because, yes… Attempting to run apt-key as a normal/unprivileged user is indeed an error.