Ubuntu tips — Fix error with security keys in apt update

When you run apt update in Ubuntu you can get following error:

Err:6 http://packages.ros.org/ros/ubuntu xenial InRelease    
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F42ED6FBAB17C654
Fetched 4678 B in 2s (1830 B/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.ros.org/ros/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F42ED6FBAB17C654
W: Failed to fetch http://packages.ros.org/ros/ubuntu/dists/xenial/InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F42ED6FBAB17C654
W: Some index files failed to download. They have been ignored, or old ones used instead.

Due to this problem apt will have problems when installing or upgrading packages.

The reason of this problem is apt failed to retrieve specified trusted key to authenticate a package. Solution is to add the missing key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

This command will download key from keyservers directly into the trusted set of keys (command man).

That’s it. Now apt update should complete without problems.