This is also a common error in a typical aptly installation. The other two common errors related to the GPG keys are: aptly publish: ERROR: unable to initialize GPG signer. Missing pubring.gpg keys and aptly mirror – gpgv: Can’t check signature: public key not found. This secret key is used when you try to publish a repository (snapshot or mirror).
root@srv-aptly ~ # aptly publish snapshot xenial-myrepo-initial Loading packages... Generating metadata files and linking package files... 15683 / 107250 [====================>--------------------------------------------------------------------------------------------------------------------] 14.62% 2h53m50s 17025 / 107250 [=====================>--------------------------------------------------------------------------------------------------------------------] 15.87% 3h5m15sFinalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: gpg: no default secret key: secret key not available gpg: signing failed: secret key not available ERROR: unable to publish: unable to detached sign file: exit status 2
You are unable to sign the Release file because the keyring secring.gpg is missing a GPG key. Just create or import from your current servers the GPG key from keyring secring.gpg (for the root user it is /root/.gnupg/secring.gpg and in general this is the default path /[my-aptly-home-directory]/.gnupg/secring.gpg).
Here is the example with the two servers, exporting from your current and importing the key in your new (the second) server:
Export the secring.gpg GPG key from your server
root@srv-aptly-1:~ # gpg --list-keys --keyring secring.gpg /root/.gnupg/secring.gpg ------------------------ pub 2048D/FDC7A25E 2017-09-16 uid My-aptly (aptly key no passphrase) <my-aptly@example.com> root@srv-aptly-1:~ # gpg --keyring secring.gpg --export --armor FDC7A25E > FDC7A25E.key root@srv-aptly-1:~ # gpg --list-secret-keys --keyring secring.gpg /root/.gnupg/secring.gpg ------------------------ sec 2048D/FDC7A25E 2017-09-16 uid My-aptly (aptly key no passphrase) <my-aptly@example.com> root@srv-aptly-1:~ # gpg --keyring secring.gpg --export-secret-key --armor FDC7A25E > FDC7A25E.sec
First is the public key (FDC7A25E.key) and second is the private key (FDC7A25E.sec). You must export them both and import them in your new server (or look below how to generate them in your server).
Copy the file to the second server (FDC7A25E.key) and then import it in keyring secring.gpg
root@srv-aptly-2:~ # cat ./FDC7A25E.key| gpg --keyring secring.gpg --import gpg: key FDC7A25E: public key "My-aptly (aptly key no passphrase) <my-aptly@example.com>" imported gpg: Total number processed: 1 gpg: imported: 1 root@srv-aptly-2:~ # gpg --keyring secring.gpg --allow-secret-key-import --armor --import FDC7A25E.sec gpg: key FDC7A25E: secret key imported gpg: key FDC7A25E: "My-aptly (aptly key no passphrase) <my-aptly@example.com>" not changed gpg: Total number processed: 1 gpg: unchanged: 1 gpg: secret keys read: 1 gpg: secret keys imported: 1
And now you can publish your repository with:
root@srv-aptly-2: ~ # aptly publish snapshot xenial-myrepo-initial ubuntu Loading packages... Generating metadata files and linking package files... Finalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: Snapshot xenial-myrepo-initial has been successfully published. Please setup your webserver to serve directory '/mnt/storage/aptly/.aptly/public' with autoindexing. Now you can add following line to apt sources: deb http://your-server/ubuntu/ xenial-myrepo main deb-src http://your-server/ubuntu/ xenial-myrepo main Don't forget to add your GPG key to apt with apt-key. You can also use `aptly serve` to publish your repositories over HTTP quickly.
The operation publish passed successfully.
Generate GPG Key
If you just came here installing a new aptly server and getting this error as mentioned above you miss a GPG key in keyring secring.gpg.
root@srv-aptly: ~# gpg --default-new-key-algo rsa4096 --gen-key --keyring secring.gpg gpg (GnuPG) 2.2.11; Copyright (C) 2018 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Note: Use "gpg --full-generate-key" for a full featured key generation dialog. GnuPG needs to construct a user ID to identify your key. Real name: My-aptly Email address: my-aptly@example.com You selected this USER-ID: "MyName <my-aptly@example.com>" Change (N)ame, (E)mail, or (O)kay/(Q)uit? O We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. gpg: key B14B67D0CF27191B marked as ultimately trusted gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/77EC42A1F16127C83509292BB14B67D0CF27191B.rev' public and secret key created and signed. Note that this key cannot be used for encryption. You may want to use the command "--edit-key" to generate a subkey for this purpose. pub rsa4096 2019-07-08 [SC] [expires: 2021-07-07] 77EC42A1F16127C83509292BB14B67D0CF27191B uid MyName <my-aptly@example.com>
NOTE
Just to note here we give you all the examples with the root user and the GPG keys are for the root user. You may use a different user for the aptly process and you must ensure the GPG keys to present for this user (the directories and files are the same, just home directory is different – the home directory of the aptly user i.e. “/[my-aptly-home-directory]/.gnupg/secring.gpg” and for all other GPG files “/[my-aptly-home-directory]/.gnupg/”).
Thanks for this. But even having a private key or keys doesn’t solve this aptly error. I am not sure of the process aptly takes to select and use one of your private keys.
I have been searching for a few days. I’ll report back here when I find the solution.
hi, DaveQB, I have the same problem with Ubuntu 20. Did you get a solution?