This is part 2 of How to install a new (custom) mime type on my Linux system using CLI tools?

Using the steps in the accepted answer at the above question, I created the following mime-type mx-publickey.xml

<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-publickey">
<comment>Custom type for public key files (plain text)</comment>
    <glob pattern="*.pub"/>

I installed it system-wide with this command:

# xdg-mime install --mode system mx-publickey.xml

I added the desired icon:

xdg-icon-resource install --context mimetypes --size 256 x-publickey-icon.png text-x-publickey

Then I tested it. My '*.pub` files still have the old association:

$ xdg-mime query filetype id_rsa_test.pub

$ xdg-mime query default text/plain

What additional steps are required to associate '*.pub` files with my new mime-type?


I performed the following steps, but *.pub public key files are still not being opened by default with Kate from Electron applications.

# xdg-mime default  org.kde.kate.desktop text/x-publickey

# xdg-mime query default text/x-publickey

$ xdg-mime query default text/x-publickey

Next I used the GUI tools (KDE System Settings > Applications > File Associations) and associated *.pub public key files with Kate. Electron applications still refuse to open *.pub files with Kate.

Electron apps previously used Okular. Afer the xdg-mime default command shown above, the Okular association is gone, but nothing has replaced it. Electron apps now present a KIO dialog asking me to pick the application to use. (That's better than forcing me to use the wrong application, but it is still not correct behavior. It appears Electron applications are looking other places for the file associations. I would like to understand that.)

Am I missing a needed .desktop file in some location?

Another thought: After the above steps, I believe I should now see an entry for text/x-publickey in /usr/share/applications/mimeinfo.cache. However, there is not one.


1 Answer 1


The shared-mime-info repository already specifies the application/pgp-keys mimetype. You can see it here:

<mime-type type="application/pgp-keys">
  <comment>PGP keys</comment>
  <expanded-acronym>Pretty Good Privacy</expanded-acronym>
  <sub-class-of type="text/plain"/>
  <generic-icon name="text-x-generic"/>
  <magic priority="50">
    <match type="string" value="-----BEGIN PGP PUBLIC KEY BLOCK-----" offset="0"/>
    <match type="string" value="-----BEGIN PGP PRIVATE KEY BLOCK-----" offset="0"/>
    <match type="big16" value="0x9501" offset="0"/>
    <match type="big16" value="0x9500" offset="0"/>
    <match type="big16" value="0x9900" offset="0"/>
    <match type="big16" value="0x9901" offset="0"/>
  <glob pattern="*.skr"/>
  <glob pattern="*.pkr"/>
  <glob pattern="*.asc" weight="10"/>
  <glob pattern="*.pgp"/>
  <glob pattern="*.gpg"/>
  <glob pattern="*.key"/>


or here on your own machine:


However, it does not use the *.pub glob pattern, probably to avoid conflicts with MS Publisher format. One workaround is just to rename the files as e.g. *.asc files. But let's continue on, assuming that renaming the files is not an option. Here is the mimeinfo file we need (note that it must be named pgp-keys.xml):

$ cat pgp-keys.xml
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
    <mime-type type="application/pgp-keys">
        <comment>PGP keys</comment>
        <expanded-acronym>Pretty Good Privacy</expanded-acronym>
        <sub-class-of type="text/plain"/>
        <generic-icon name="text-x-generic"/>
        <magic priority="10">
          <match value="-----BEGIN PGP PUBLIC KEY BLOCK-----" type="string" offset="0"/>
        <glob weight="10" pattern="*.pub"/>

The advantage of the "magic" part is that it will look at the beginning of the file for this string, then determine the mimetype based on whether or not it matches. This means that files with mimetype application/vnd.ms-publisher can still have the .pub file extension and live in relative harmony alongside public keys that also have the .pub file extension. To achieve this, we must install the mimeinfo file.

To install it for a single user:

xdg-mime install --mode user pgp-keys.xml
update-mime-database ~/.local/share/mime

To install it system-wide:

sudo xdg-mime install --mode system pgp-keys.xml
sudo /usr/bin/update-mime-database /usr/share/mime

I've tested the outcome with an example public key from here:


and an example MS Publisher file from here:


You can try it yourself with the git repository here:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .