# keygen · Chromia Docs (concept)

> The keygen command (chr keygen) generates public and private key pairs for Chromia CLI operations. Generate a key pair with a custom key ID:

Source: https://docs.chromia.com/build/cli/commands/keygen/

# keygen

On this page

* [Generate keys](#generate-keys)
* [Basic usage](#basic-usage)
* [Generate with file path](#generate-with-file-path)
* [Recover from mnemonic](#recover-from-mnemonic)
* [Dry run](#dry-run)
* [Default behavior](#default-behavior)
* [Next steps](#next-steps)
* [Command reference](#command-reference)
* [Using your key pair](#using-your-key-pair)

## Generate keys

The keygen command (`chr keygen`) generates public and private key pairs for Chromia CLI operations.

### Basic usage

Generate a key pair with a custom key ID:

Terminal

```
chr keygen --key-id=<value>
```

This creates three files in the `~/.chromia` directory:

* `key-id` - Contains the private key
* `key-id.pubkey` - Contains the public key
* `key-id_mnemonic` - Contains the mnemonic phrase for recovery

### Generate with file path

Generate a key pair and save it to a specific file:

Terminal

```
chr keygen --file=<path>
```

This creates two files at the specified location:

* `file_name` - Contains the keypair
* `file_name_mnemonic` - Contains the mnemonic phrase

### Recover from mnemonic

Recover a key pair from a mnemonic phrase:

Terminal

```
chr keygen --mnemonic "lift employ roast rotate liar holiday sun fever output magnet..."
```

Use the `--key-id` or `--file` option along with `--mnemonic` to specify where to save the recovered key:

Terminal

```
chr keygen --mnemonic "your mnemonic phrase" --key-id=recovered_key
```

### Dry run

See what keys would be generated without saving to disk:

Terminal

```
chr keygen --dry
```

### Default behavior

By default, keys are generated with the default key ID `chromia_key` and saved in the `.chromia` folder as
`chromia_key.pubkey` and `chromia_key`:

Terminal

```
chr keygen
```

### Next steps

After generating your key pair, learn how to [manage and configure it](https://docs.chromia.com/build/cli/key-pair-management/).

---

## Command reference

Plain text

```
Usage: chr keygen [<options>]

  Generates public/private key pair

File format:
  -f, --file=<path>        Set file to save keypair to explicitly
  --get-pubkey[=<key-id>]  Print the active public key. If no key-id is
                           specified, the key is determined from your
                           configuration; otherwise, retrieves the public key
                           for the given key-id.
  --dry                    Perform dry run, prints keys in terminal and does
                           not save keys to disk
  --key-id=<value>         Name the generated key with an id

Options:
  -m, --mnemonic=<text>  Mnemonic word list, words separated by space, e.g:
                         "lift employ roast rotate liar holiday sun fever
                         output magnet...""
  -h, --help             Show this message and exit
```

### Using your key pair

To use a key pair by its key ID, set the property `key.id = <key_id>` in your configuration file (`.chromia/config`).

If your `TEXT` string is `myKey` then the public key is stored as `myKey.pubkey` and private key as `myKey`. To use a
key pair by its key ID, set the property `key.id = <key_id>` in your Chromia configuration (`.chromia/config`) file. If
the config file does not exist, then you can create one in the `.chromia` folder.

* **Windows:** `C:\Users\<YourUsername>\.chromia\config`
* **macOS and Linux:** `/Users/<YourUsername>/.chromia/config` or `/home/<YourUsername>/.chromia/config`

[View this page on docs.chromia.com](https://docs.chromia.com/build/cli/commands/keygen/)Content mirrored from the live docs
