onlykey-cli
OnlyKey-cli - A command line interface to the OnlyKey (Similar functionality to OnlyKey App) that can be used for configuration, scripting, and testing.
python-onlykey 1.3.1 is the release for OnlyKey firmware 3.1.0. It needs Python 3.10 or newer and adds:
- Post-quantum keys: ML-KEM-768 and X-Wing key types for
setkeyandgenkey, composite PQC PGP keys withloadpqc, and thesignpqcanddecryptpqcdevice operations - age-plugin-onlykey, with derived and stored X-Wing keys
- The firmware 3.1.0 settings
storedkeymode,derivedkeymode,webderivemodeandwebcryptpolicy(user input modes), andcapabilities
setpqc and 2ndprofilemode have been removed: use loadpqc (or setkey PQC1-PQC4 p) instead of setpqc. A second profile is always encrypted with its own PIN.
Installation
The stand-alone EXE is onlykey-cli 1.2.9. It does not have the firmware 3.1.0 commands (post-quantum keys, age and the new settings); for those, install python-onlykey 1.3.1 with pip as below.
Stand-alone EXE (no install required) — download and run the EXE to open OnlyKey CLI interactive mode, or run it directly from the command line:
C:\ onlykey-cli.exe getlabels
Install with dependencies
- Python 3.10 or newer and pip3 are required. To set up a Python environment on Windows we recommend Anaconda: https://www.anaconda.com/download/#windows
- From an administrator command prompt run:
pip3 install hidapi==0.9.0 onlykey
You should see a message showing where the executable is installed. This is usually c:\python39\scripts\onlykey-cli.exe
Python 3.10 or newer and pip3 are required. To set up a Python environment on macOS we recommend Anaconda: https://www.anaconda.com/download/#macos
$ brew install libusb
$ pip3 install onlykey
On an Intel Mac, install cryptography version 48 or older first if you want the age plugin: pip3 install "cryptography<49".
In order for non-root users in Linux to be able to communicate with OnlyKey, a udev rule must be created as described here.
Ubuntu / Debian
Since Debian 12 “bookworm” and Ubuntu 23.04, the system Python is marked externally-managed (PEP 668), so installing into the system Python with pip3 install onlykey is blocked. Install with pipx (recommended) or inside a virtual environment instead. Other distributions that enforce PEP 668 should follow the same approach.
Option A — pipx (recommended)
$ sudo apt update && sudo apt upgrade
$ sudo apt install pipx python3-tk libusb-1.0-0-dev libudev-dev
$ pipx install --system-site-packages onlykey
$ pipx ensurepath
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
Option B — virtual environment (venv)
$ sudo apt update && sudo apt upgrade
$ sudo apt install python3-pip python3-venv python3-tk libusb-1.0-0-dev libudev-dev
$ python3 -m venv ~/onlykey-venv
$ ~/onlykey-venv/bin/pip3 install onlykey
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
With venv, run the CLI as ~/onlykey-venv/bin/onlykey-cli (or source ~/onlykey-venv/bin/activate first, then use onlykey-cli directly).
RedHat
$ yum update
$ yum install python3-pip python3-devel python3-tk libusb-devel libudev-devel \
gcc redhat-rpm-config
$ pip3 install onlykey
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
Fedora
$ dnf install python3-pip python3-devel python3-tkinter libusb-devel libudev-devel \
gcc redhat-rpm-config
$ pip3 install onlykey
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
OpenSUSE
$ zypper install python3-pip python3-devel python3-tk libusb-1_0-devel libudev-devel
$ pip3 install onlykey
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
Arch Linux
$ sudo pacman -Sy git python3-setuptools python3 libusb python3-pip
$ pip3 install onlykey
$ wget https://raw.githubusercontent.com/trustcrypto/trustcrypto.github.io/pages/49-onlykey.rules
$ sudo cp 49-onlykey.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger
FreeBSD
See the forum thread here.
age plugin
To also install age-plugin-onlykey, add the age extra (it adds cryptography and kyber-py):
$ pip3 install "onlykey[age]"
With pipx: pipx install --system-site-packages "onlykey[age]".
Node.js for loadpqc
loadpqc reads composite post-quantum PGP key files with the OpenPGP.js copy that ships with python-onlykey, which runs under Node.js. Install Node.js and make sure node is on your PATH before using loadpqc.
QuickStart
Usage: onlykey-cli [OPTIONS]
Setup Options
init
A command line tool for setting PIN on OnlyKey (Initial Configuration)
General Options
version
Displays the version of the app
capabilities
Asks the firmware what it supports (needs firmware with protocol v1 or later): firmware version,
key types, build flags (PQC, DUO, debug, whether the no-press user input mode is compiled in) and
the user input modes each of derivedkeymode / storedkeymode / webderivemode accepts. Older
firmware prints that it does not report capabilities.
fwversion
Displays the version of the OnlyKey firmware
wink
OnlyKey flashes blue (winks), may be used for visual confirmation of connectivity
getlabels
Returns slot labels
settime
A command for setting time on OnlyKey, time is needed for TOTP (Google Authenticator)
getkeylabels
Returns key labels for RSA keys 1-4 and ECC keys 1-16
rng [type]
Access OnlyKey TRNG to generate random numbers:
- [type] must be one of the following:
- hexbytes - Output hex encoded random bytes. Default 8 bytes; Maximum 255 bytes. Specify number of bytes to return with --count
i.e. ‘onlykey-cli rng hexbytes --count 32’ - feedkernel - Feed random bytes to /dev/random.
- hexbytes - Output hex encoded random bytes. Default 8 bytes; Maximum 255 bytes. Specify number of bytes to return with --count
OnlyKey Preferences Options
idletimeout [num]
OnlyKey locks after ideletimeout is reached (1 – 255 minutes; default = 30; 0 to disable). More info
wipemode [num]
Configure how the OnlyKey responds to
a factory reset. WARNING - Setting to Full Wipe mode cannot be changed.
1 = Sensitive Data Only (default); 2 = Full Wipe (recommended for plausible deniability users) Entire device is wiped. Firmware must be reloaded. More info
keylayout [num]
Set keyboard layout
- 1 - USA_ENGLISH (Default)
- 2 - CANADIAN_FRENCH
- 3 - CANADIAN_MULTILINGUAL
- 4 - DANISH
- 5 - FINNISH
- 6 - FRENCH
- 7 - FRENCH_BELGIAN
- 8 - FRENCH_SWISS
- 9 - GERMAN
- 10 - GERMAN_MAC
- 11 - GERMAN_SWISS
- 12 - ICELANDIC
- 13 - IRISH
- 14 - ITALIAN
- 15 - NORWEGIAN
- 16 - PORTUGUESE
- 17 - PORTUGUESE_BRAZILIAN
- 18 - SPANISH
- 19 - SPANISH_LATIN_AMERICA
- 20 - SWEDISH
- 21 - TURKISH
- 22 - UNITED_KINGDOM
- 23 - US_INTERNATIONAL
- 24 - CZECH
- 25 - SERBIAN_LATIN_ONLY
- 26 - HUNGARIAN
- 27 - DANISH MAC
- 28 - US_DVORAK
keytypespeed [num]
1 = slowest; 10 = fastest [7 = default]
More info
ledbrightness [num]
1 = dimmest; 10 = brightest [8 = default]
More info
touchsense [num]
Change the OnlyKey’s button touch sensitivity.
WARNING: Setting button’s touch sensitivity lower than 5 is not recommended as this could result in inadvertent button press.
2 = highest sensitivity; 100 = lowest sensitivity [12 = default]
storedkeymode [num]
User input required to use a stored key (RSA1-RSA4 / PQC1-PQC4 and ECC1-ECC16 - any protocol: SSH, PGP, age, composite PQC)
0 = Challenge Code Required; 1 = Button Press Required (default); 2 = No press (unattended agents - only honoured by firmware built with OK_ALLOW_NO_PRESS, refused otherwise)
More info
derivedkeymode [num]
User input required to use a derived key (SSH/GPG agent identities)
0 = Challenge Code Required; 1 = Button Press Required (default); 2 = No press (as above)
More info
webderivemode [num]
User input required to use a web and agent derived key - the OnlyKey web app (age pages and Post-Quantum Vault) and derived X-Wing age decryption with age-plugin-onlykey. The key itself never changes with this setting.
0 = Challenge Code Required (the web app / age plugin shows the 3 digits); 1 = Button Press Required (default); 2 = No press (press-free per-site decryption). More info
webcryptpolicy [num]
What the OnlyKey web app (apps.crp.to / apps.onlykey.io) may do with this OnlyKey. Requires firmware v3.1.0 or newer and config mode.
0 = Derived keys only (stored keys / PGP not available to the web app); 1 = Also allow stored keys (PGP) from the web app; 2 = Turn the web app extension off entirely (derived keys included); 3 = same as 2
Until this is set the key behaves as older firmware did: the web app may use stored keys. More info
hmackeymode [num]
Enable or disable button press for HMAC challenge-response
0 = Button Press Required (default); 1 = Button Press Not Required.
More info
backupkeymode [num]
1 = Lock backup key so this may not be changed on device
WARNING - Once set to “Locked” this cannot be changed unless a factory reset occurs.
More info
sysadminmode
Enable or disable Sysadmin Mode, which lets slots store and type modifier keys such as CTRL-ALT-DEL
0 = Off (default); 1 = On
More info
lockbutton
One of the buttons on OnlyKey can be configured as a lock button.
0 = Disable lockbutton; 1-6 = The selected button
More info
Slot Config Options
setslot [id] [type] [value]
- [id] must be slot number 1a - 6b for OnlyKey or 1-24 for OnlyKey DUO
- [type] must be one of the following:
- label - set slots (1a - 6b) to have a descriptive label i.e. My Google Acct
- url - URL to login page
- delay1 - set a 0 - 9 second delay
- addchar1 - Additional character before username 1 for TAB, 0 to clear
- username - Username to login
- addchar2 - Additional character after username 1 for TAB, 2 for RETURN
- delay2 - set a 0 - 9 second delay
- password - Password to login
- addchar3 - Additional character after password 1 for TAB, 2 for RETURN
- delay3 - set a 0 - 9 second delay
- addchar4 - Additional character before OTP 1 for TAB
- 2fa - type of two factor authentication
- g - Google Authenticator
- y - Yubico OTP
- u - U2F
- totpkey - Google Authenticator key
- addchar5 - Additional character after OTP 2 for RETURN
wipeslot [id]
- [id] must be slot number 1a - 6b for OnlyKey or 1-24 for OnlyKey DUO
Key Config Options
setkey [key slot] [type] [features] [hex key]
Sets raw private keys and key labels, to set PEM format keys use the OnlyKey App
- [key slot] must be key number RSA1 - RSA4, PQC1 - PQC4, ECC1 - ECC16, HMAC1 - HMAC2
- [type] must be one of the following:
- label - set to have a descriptive key label i.e. My GPG signing key
- p - Composite PQC PGP seed blob (160 bytes; PQC1 - PQC4 only, see loadpqc)
- x - Ed25519 Key Type (32 bytes, signing)
- n - NIST256P1 Key Type (32 bytes)
- s - SECP256K1 Key Type (32 bytes)
- c - X25519 (Curve25519) Key Type (32 bytes, decryption only)
- m - ML-KEM-768 seed (64 bytes, decryption only)
- w - X-Wing seed (32 bytes, decryption only)
- 2 - RSA Key Type 2048bits (256 bytes)
- 4 - RSA Key Type 4096bits (512 bytes)
- h - HMAC Key Type (20 bytes)
- [features] must be one of the following:
- s - Use for signing
- d - Use for decryption
- b - Use for encryption/decryption of backups
- For setting keys see examples here.
genkey [key slot] [type] [features]
Generates random private key on device
- [key slot] must be key number ECC1 - ECC16 (only ECC keys supported)
- [type] must be one of the following:
- x - Ed25519 Key Type
- n - NIST256P1 Key Type
- s - SECP256K1 Key Type
- c - X25519 (Curve25519) Key Type
- m - ML-KEM-768 Key Type
- w - X-Wing Key Type
- [features] must be one of the following:
- s - Use for signing
- d - Use for decryption
- b - Use for encryption/decryption of backups
- For generating key see example here.
loadpqc [keyfile] [PQC1-PQC4] [passphrase]
Loads a composite post-quantum PGP private key (ML-KEM-768 + X25519 / ML-DSA-65 + Ed25519, IETF OpenPGP-PQC) from an armored key file into one of the four PQC slots (the RSA slots). Requires firmware v3.1.0 or newer, config mode, and Node.js on PATH (the key file is parsed with the bundled OpenPGP.js). A raw 160-byte seed blob can instead be loaded with setkey PQC1 p [hex].
signpqc [PQC1-PQC4] [ecc|pqc] [digest hex | file]
Signs a digest with one half of the composite PQC PGP key in a PQC slot: ecc gives a 64-byte Ed25519 signature, pqc a 3309-byte ML-DSA-65 signature, printed as hex. Requires firmware v3.1.0 or newer and asks you to confirm on the OnlyKey (stored keys user input mode).
This is the device operation, not a PGP signer: a composite OpenPGP signature is the two halves together, and building the OpenPGP packet is up to the calling program. To sign messages, use the web app.
decryptpqc [PQC1-PQC4] [hex | file]
Decapsulates with one half of the composite PQC PGP key in a PQC slot and prints the 32-byte shared secret as hex. The half is chosen by the input size: a 32-byte X25519 point uses the X25519 half, a 1088-byte ML-KEM-768 ciphertext the ML-KEM half. Requires firmware v3.1.0 or newer and asks you to confirm on the OnlyKey.
Like signpqc, it is a building block: recovering an OpenPGP session key needs the RFC 9980 key combiner and an AES key unwrap, which the calling program does. To decrypt messages, use the web app.
wipekey [key id]
Erases key stored at [key id]
- [key id] must be key number RSA1 - RSA4, PQC1 - PQC4, ECC1 - ECC16, HMAC1 - HMAC2
age plugin (age-plugin-onlykey)
See age with OnlyKey for a full walkthrough. Installed with pip3 install "onlykey[age]". Lets age encrypt to and decrypt with an OnlyKey using X-Wing (ML-KEM-768 + X25519) keys. Requires firmware v3.1.0 or newer.
age-plugin-onlykey --generate- generate an X-Wing key on the deviceage-plugin-onlykey --identity/--recipient- print the identity file line / the recipient for a stored keyage-plugin-onlykey --derived --label NAME --recipient- a derived recipient for a label; the private key never leaves the device and the same label gives the same recipient in the OnlyKey web app- add
--nativeto--recipientto print the same key as age’s own post-quantum recipient (age1pq1...). age 1.3+, typage, and rage or older age withage-plugin-pqcan then encrypt to the OnlyKey without this plugin installed; decryption still uses the OnlyKey identity.
Files are standard age v1 (mlkem768x25519 stanzas per the age specification): what the plugin or the OnlyKey web app writes opens in age, rage and typage, and the other way around. Tested against age 1.3.2 and 1.1.1, rage 0.12.1 and typage 0.3.1.
FIDO2 Config Options
ping
Sends a FIDO2 transaction to the device, which immediately echoes the same data back. This command is defined to be a uniform function for debugging, latency and performance measurements (CTAPHID_PING).
set-pin
Set new FIDO PIN, this is the PIN entered via keyboard and used for FIDO2 register/login (not the OnlyKey PIN entered on device).
change-pin
Change FIDO PIN, this is the PIN entered via keyboard and used for FIDO2 register/login (not the OnlyKey PIN entered on device, to change that PIN use the OnlyKey Desktop App).
credential [operation] [credential ID]
- [operation] must be one of the following:
- info - Display number of existing resident keys and remaining space.
- ls - List resident keys.
- rm [credential ID] - Remove resident keys, example here.
reset
Reset wipes all FIDO U2F and FIDO2 credentials!!! It is highly recommended to backup device prior to reset.
Running Command Options
You can run commands in two ways:
1) Directly in terminal
Like this:
$ onlykey-cli getlabels
Slot 1a:
Slot 1b:
Slot 2a:
Slot 2b:
Slot 3a:
Slot 3b:
Slot 4a:
Slot 4b:
Slot 5a:
Slot 5b:
Slot 6a:
Slot 6b:
$ onlykey-cli setslot 1a label ok
Successfully set Label
$ onlykey-cli getlabels
Slot 1a: ok
Slot 1b:
Slot 2a:
Slot 2b:
Slot 3a:
Slot 3b:
Slot 4a:
Slot 4b:
Slot 5a:
Slot 5b:
Slot 6a:
Slot 6b:
2) Interactive Mode
Or you can run commands in an interactive shell like this:
$ onlykey-cli
OnlyKey CLI v1.3.1
Press the right arrow to insert the suggestion.
Press Control-C to retry. Control-D to exit.
OnlyKey> getlabels
Slot 1a:
Slot 1b:
Slot 2a:
Slot 2b:
Slot 3a:
Slot 3b:
Slot 4a:
Slot 4b:
Slot 5a:
Slot 5b:
Slot 6a:
Slot 6b:
OnlyKey> setslot 1a label ok
Successfully set Label
OnlyKey> getlabels
Slot 1a: ok
Slot 1b:
Slot 2a:
Slot 2b:
Slot 3a:
Slot 3b:
Slot 4a:
Slot 4b:
Slot 5a:
Slot 5b:
Slot 6a:
Slot 6b:
OnlyKey> setslot 1a url accounts.google.com
Successfully set URL
OnlyKey> setslot 1a addchar1 2
Successfully set Character1
OnlyKey> setslot 1a delay1 2
Successfully set Delay1
OnlyKey> setslot 1a username onlykey.1234
Successfully set Username
OnlyKey> setslot 1a addchar2 2
Successfully set Character2
OnlyKey> setslot 1a delay2 2
Successfully set Delay2
OnlyKey> setslot 1a password
Type Control-T to toggle password visible.
Password: *********
Successfully set Password
OnlyKey> setslot 1a addchar3 2
Successfully set Character3
OnlyKey> setslot 1a delay3 2
Successfully set Delay3
OnlyKey> setslot 1a 2fa g
Successfully set 2FA Type
OnlyKey> setslot 1a totpkey
Type Control-T to toggle password visible.
Password: ********************************
Successfully set TOTP Key
OnlyKey> setslot 1a addchar4 2
Successfully set Character4
OnlyKey>
Bye!
Examples
Writing Private Keys and Passwords
Keys/passwords are masked when entered and should only be set from interactive mode and not directly from terminal. Entering directly from terminal is not secure as command history is stored.
Setkey Examples
To set key a device must first be put into config mode.
Set HMAC key 1 to a custom value
$ onlykey-cli
OnlyKey> setkey HMAC1 h
Type Control-T to toggle password visible.
Password/Key: ****************************************
Successfully set ECC Key
HMAC key must be 20 bytes, h is HMAC type
Set HMAC key 2 to a custom value
$ onlykey-cli
OnlyKey> setkey HMAC2 h
Type Control-T to toggle password visible.
Password/Key: ****************************************
Successfully set ECC Key
HMAC key must be 20 bytes, h is HMAC type
Set ECC key in slot ECC1 to a custom value (Slots ECC1-ECC16 are available for ECC keys. Supported ECC curves X25519(x), NIST256P1(n), SECP256K1(s))
$ onlykey-cli
OnlyKey> setkey ECC1 x
Type Control-T to toggle password visible.
Password/Key: *************************************************************
Successfully set ECC Key
ECC key must be 32 bytes, x is X25519 type
Genkey Examples
To set key a device must first be put into config mode.
Generate ECC key in slot ECC1 to a custom value (Slots ECC1-ECC16 are available for ECC keys. Supported ECC curves X25519(x), NIST256P1(n), SECP256K1(s))
$ onlykey-cli
OnlyKey> genkey ECC1 x
Successfully set ECC Key
Scripting Example
Set time on OnlyKey (required for TOTP)
$ onlykey-cli settime
This can be added to scripts such as the UDEV rule to automatically set time when device is inserted into USB port. See example here
Scripted provisioning of an OnlyKey slots and keys can be done by creating a script that sets multiple values on OnlyKey
List and Remove FIDO2 Resident Key
List current resident keys:
onlykey-cli credential ls

Remove a resident key by credential ID
onlykey-cli credential rm eu7LPIjTNwIJt2Ws9LWJlXkiNKaueSEEGteZM2MT/lZtEuYo49V6deCiIRMb6EDC29XG13nBL60+Yx+6hxSUYS1uxX9+AA==
Once removed, list current resident keys to verify:

Source
Third-party code
onlykey/openpgp_bridge/openpgp.js is OpenPGP.js v6, licensed under the GNU LGPL v3. loadpqc runs it (through Node.js) to read composite PQC PGP key files.