> For the complete documentation index, see [llms.txt](https://docs.k9.io/key9-identity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.k9.io/key9-identity/ssh/installation-and-setup/quickstart/3.-generating-keys-and-certificates-for-the-yubikey.md).

# 3. Generating Keys and Certificates for the Yubikey

In a terminal window, we will first generate a new key in PEM format. If successful, your Yubikey should start flashing, and you should see "Successfully generated a new private key."

`$ yubico-piv-tool -s 9a -a generate -o public.pem`

Create a self-signed certificate for that key. The only use for the X.509 certificate is to satisfy PIV/PKCS #11 lib. It needs to be able to extract the public-key from the smartcard, and to do that through the X.509 certificate. &#x20;

`$ yubico-piv-tool -a verify-pin -a selfsign-certificate -s 9a -S "/CN=SSH key/" -i public.pem -o cert.pem`

If the command is successful, you will be prompted to "Enter PIN:". This is the PIN you set using the "Yubikey Manager". If the command is successful, you should see "Successfully generated a new self-signed certificate".

We can now load the certificate.

`$ yubico-piv-tool -a import-certificate -s 9a -i cert.pem`

&#x20;If successful, you should see “Successfully imported a new certificate.”


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.k9.io/key9-identity/ssh/installation-and-setup/quickstart/3.-generating-keys-and-certificates-for-the-yubikey.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
