---
title: "Authentication: Client Certificate Usage"
description: "Authenticate client applications to RavenDB using X.509 client certificates with per-database access permissions and security clearance levels."
url: "https://docs.ravendb.net/6.2/server/security/authentication/client-certificate-usage"
version: "6.2"
---

# Authentication: Client Certificate Usage

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

## Client certificate usage

> **Note**
>
> - Once a RavenDB server runs with a server certificate, clients must present a trusted
>   client certificate to connect to it.
>
> - This article explains how to obtain your first admin client certificate, and how to
>   start working with client certificates afterward.
>
> - Read about the logic and rationale behind RavenDB's client certificates in
>   [The RavenDB security authorization approach](https://docs.ravendb.net/6.2/server/security/authentication/certificate-management.md#the-ravendb-security-authorization-approach)
>   to understand how security clearances and per-database permissions work before you assign them to your client certificates.
>
> - In this article:
>   - [Obtaining your first admin client certificate](#obtaining-your-first-admin-client-certificate)
>     - [Using the RavenDB CLI](#using-the-ravendb-cli)
>     - [Using PowerShell and wget on Windows](#using-powershell-and-wget-on-windows)
>     - [Using cURL on Linux](#using-curl-on-linux)
>   - [Using client certificates](#using-client-certificates)

## Obtaining your first admin client certificate {#obtaining-your-first-admin-client-certificate}

When a RavenDB server runs with a server certificate for the first time, no client
certificates are registered on the server yet.  
The first thing an administrator does is generate or register an admin client certificate.

An admin client certificate is a client certificate that carries `Cluster Admin` security
clearance.  
It is separate from the server certificate (which may be a Let's Encrypt certificate); it is
the certificate that administrators and applications present to authenticate to the server.

> **Note**
>
> This step is only required for a **manual** secure setup.  
> If you use the automated [Setup Wizard](https://docs.ravendb.net/6.2/start/installation/setup-wizard/overview.md),
> an admin client certificate is generated for you as part of the wizard.

### Using the RavenDB CLI

If you have access to the server, the simplest way to generate a client certificate is to
use the RavenDB CLI:

```text
ravendb> generateClientCert <name> <path-to-output-folder> <number of months until expiration> [password]
```

This generates a new certificate with a `Cluster Admin` security clearance.

To have RavenDB trust a client certificate that you already own, run:

```text
ravendb> trustClientCert <name> <path-to-pfx> [password]
```

The certificate is registered as a trusted certificate with a `Cluster Admin` security clearance.

### Using PowerShell and wget on Windows

You can use a client to make an HTTP request to the server.  
You have not generated a client certificate yet, so this first request is authenticated with
the server certificate itself.  
RavenDB trusts its own server certificate as a client certificate with `Cluster Admin`
clearance, which authorizes it to create your first client certificate.

Assume the server was started with the following
[settings.json](https://docs.ravendb.net/6.2/server/configuration/configuration-options.md#settingsjson):

```json
{
    "ServerUrl": "https://rvn-srv-1:8080",
    "Setup.Mode": "None",
    "DataDir": "c:/RavenData",
    "Security.Certificate.Path": "c:/secrets/server.pfx",
    "Security.Certificate.Password": "s3cr7t p@$$w0rd"
}
```

Use wget to request a `Cluster Admin` certificate.  
This is the payload of the POST request:

```json
{
    "Name": "cluster.admin.client.certificate",
    "SecurityClearance": "ClusterAdmin",
    "Password": "p@$$w0rd"
}
```

First, load the server certificate:

```powershell
$cert = Get-PfxCertificate -FilePath c:/secrets/server.pfx
```

Then make the request:

```powershell
wget -UseBasicParsing -Method POST -Certificate $cert -OutFile "cluster.admin.cert.zip" -Body '{"Name": "cluster.admin.client.certificate","SecurityClearance": "ClusterAdmin","Password": "p@$$w0rd"}' -ContentType application/json "https://rvn-srv-1:8080/admin/certificates"
```

### Using cURL on Linux

You have not generated a client certificate yet, so this first request is authenticated with
the server certificate itself.  
RavenDB trusts its own server certificate as a client certificate with `Cluster Admin`
clearance, which authorizes it to create your first client certificate.  
First, convert the .pfx certificate to .pem:

```bash
openssl pkcs12 -in cluster.server.certificate.example.pfx -out server.pem -clcerts
```

> **Note**
>
> You must provide a password when creating the .pem file.  
> cURL only accepts a password-protected certificate.

Then make the request:

```bash
curl -X POST -H "Content-Type: application/json" -d '{"Name": "cluster.admin.client.certificate","SecurityClearance": "ClusterAdmin","Password": "p@$$w0rd"}' -o cluster.admin.cert.zip https://rvn-srv-1:8080/admin/certificates --cert /home/secrets/server.pem:pem_password
```

## Using client certificates {#using-client-certificates}

Once you have the admin client certificate, you can access the server or cluster using
Studio, the Client API, or any other client.

> **Note**
>
> [Read here](https://docs.ravendb.net/6.2/studio/overview.md#accessing-studio-after-setup) about gaining
> management access to RavenDB after setup.

It is recommended to generate additional certificates with reduced access rights for
applications and users.  
Wiring a certificate in the RavenDB Client is described in the
[setting up authentication and authorization](https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization.md#example---initializing-document-store-with-a-client-certificate)
section of the Client API.

## See also

- [Certificate Management](https://docs.ravendb.net/6.2/server/security/authentication/certificate-management.md)
- [generateClientCert (RavenDB CLI)](https://docs.ravendb.net/6.2/server/administration/cli.md)
- [Setting up Authentication and Authorization](https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization.md)
