Log in
About 2176 words
unifi login signs in to a UniFi console and creates a context for it. There are three ways to sign in, and they differ in where the API key comes from and which path requests take.
| Mode | Key from | Reaches | Use it when |
|---|---|---|---|
| Cloud (default) | unifi.ui.com, Settings → API Keys | every console of your UI account, through the cloud connector | you're not on the console's network, or you manage several consoles |
--local | the console, Settings → Control Plane → Integrations | that one console, directly | you're on its network and want no cloud in the path |
--sso | created for you after e-mail, password and one-time code | same as cloud | you'd rather not create a key by hand; experimental |
Sign in through the cloud
Open unifi.ui.com and sign in with your UI account.
Go to Settings → API Keys and create a key. Copy it right away, because the page shows it once.
Run the sign-in:
unifi login
On a terminal, unifi login explains these steps, offers to open the API keys page in your browser (suppress that with --no-browser), and asks for the key with hidden input. It then verifies the key against the Site Manager API, lists the consoles of the account, and lets you pick the console and its default site.
The key you get from unifi.ui.com is a Site Manager API key. Requests to the Network application travel to api.ui.com and from there through the cloud connector to your console, so the console has to be online and connected to the UI cloud.
If the account has several consoles and you want all of them, create one context per console in one go:
unifi login --all-consolesThe contexts share one account entry and one stored key.
Sign in to a console on your network
In the UniFi Network application, go to Settings → Control Plane → Integrations and create an API key.
Sign in with the console's address:
unifi login --local --address https://192.168.1.1
On a terminal the sign-in asks for the key, for a name for the context, and, when the console has several sites, for the default one. --name and --site answer those questions up front.
The address is the console itself, such as https://unifi.local or https://192.168.1.1; unifi-cli adds the /proxy/network path that UniFi OS consoles serve the Network application under. A self-hosted UniFi Network Server has no such prefix and listens on port 8443. Give it an address with an explicit path and unifi-cli uses the address as it is: --address https://controller.example.net:8443/.
A local key belongs to the administrator who created it. A key of a view-only administrator can read everything and change nothing, which is a sensible choice for monitoring and for agents that should only look.
Self-signed certificates
Consoles ship with a certificate your machine doesn't trust. unifi login --local notices, shows the certificate's SHA-256 fingerprint, and offers three ways on: pin it, skip verification, or abort.
Pin the certificate. This is the choice to make. unifi-cli saves the certificate the console presents under certs/ in the configuration directory, records it as the controller's caFile, and from then on trusts exactly that certificate for this controller. A different certificate later is an error of its own: unifi-cli says that the certificate no longer matches the pinned one, prints both SHA-256 fingerprints, the pinned and the presented, and tells you how to pin the new one once you've checked it. The troubleshooting guide shows the message. Compare the fingerprint with the one the console's web interface shows before you agree.
Scripts pass --pin-certificate and get the fingerprint on standard error:
$ unifi login --local --address https://localhost:8443 --name demo --pin-certificate
● Pinning the certificate the controller presents.
→ SHA-256 fingerprint:
37:73:CD:86:FC:EB:82:86:AA:C1:B5:AB:16:F6:50:52:1C:34:A0:68:92:6B:43:5B:A2:9E:BC:66:E5:B4:9A:FD
→ Issued to unifi-mock, valid until 30 November 2027.
✓ Signed in. The context "demo" is ready.Pinning has one limitation. A certificate has to be valid for the address you typed: a factory certificate issued to unifi.local can't be pinned for https://192.168.1.1. unifi-cli says so and suggests the name the certificate was issued to; sign in with that name as the address, or skip verification.
Bring your own certificate file.--ca-file <file.pem> trusts a certificate or an authority you exported yourself, which is the right tool when the console has a certificate from your own CA.
Skip verification.--insecure-skip-tls-verify turns verification off for this controller. The connection is still encrypted, but to whoever answers, and that party receives your API key. It's the weakest of the three.
All of this is stored on the controller entry in the configuration (caFile, insecureSkipTlsVerify) and can be changed later with unifi config edit. unifi ctx describe shows which one a context uses in its TLS line. Connections to unifi.ui.com are always verified against your system's certificate authorities; the TLS flags don't apply to them.
Sign in with e-mail and password (experimental)
unifi login --sso --username [email protected]This asks for your UI account's password and the current code of your authenticator app, signs in to the UI account service, creates a Site Manager API key for you, and continues as the cloud sign-in.
What it does, precisely:
- The key is named after your machine,
unifi-cli (<hostname>), so you can tell it apart at unifi.ui.com. - It's valid for a year unless you choose otherwise with
--key-expiration(1m,3m,6m,1y,3yornever). - If the account already has a key of that name, a terminal sign-in asks whether to replace it. Scripts pass
--replace-key; without it the old key stays and the new one gets a number. - Signing in again with the same e-mail address reuses the account entry in your configuration.
- The password is never stored. The session of the sign-in is stored next to the key, in the credential store, for one purpose: so that
unifi logoutcan revoke the key later.--no-store-sessionleaves it out, and logout then asks for your password again.
The flow has been confirmed against the real service. It stays experimental all the same, because sign-in and key creation both use endpoints of the UI account service that Ubiquiti doesn't document, and a change on their side can break it without notice. Creating the key by hand always works.
Sign in without a terminal
Scripts, CI jobs and agents pass everything as flags. The API key is read from --api-key-stdin, from the UNIFI_API_KEY environment variable, or from --api-key, in that order of preference. Avoid --api-key: a command-line argument is visible to every user of the machine in the process list and is written to your shell history, and unifi login warns about it.
# Key on standard input, console and site as flags
unifi login --api-key-stdin --console "Dream Machine" --site Default --name home < key.txt
# Local controller, key from the environment, certificate pinned
UNIFI_API_KEY="$(pass show unifi/home)" unifi login --local \
--address https://192.168.1.1 --pin-certificate --name home
# Experimental: e-mail sign-in with a key that expires after three months
unifi login --sso --username [email protected] --password-stdin \
--one-time-code 123456 --key-expiration 3m < password.txtWithout a terminal, unifi login never guesses. When the account has more than one console and neither --console nor --all-consoles is given, it fails and lists the consoles it found.
Two flags control the result. --name sets the context name; an existing context of that name is replaced, which is how you sign a context in again after rotating a key. --no-switch keeps the current context as it is.
CI without a stored key
A CI job doesn't need unifi login to store anything. UNIFI_API_KEY overrides every stored key for every account, so a job can commit a configuration file with the contexts and inject the key as a secret:
export UNIFI_CONFIG=ci/unifi-config.yaml
export UNIFI_API_KEY="${UNIFI_API_KEY_FROM_CI_SECRET}"
unifi diff -f site/ --recursiveexamples/config.yaml is such a file for the demo controller.
In a container or on a runner where a job does call unifi login, set UNIFI_CREDENTIAL_STORE=file so the key goes to credentials.yaml next to the configuration file instead of a keychain that isn't there.
Where the key is stored
unifi-cli asks three stores in order and uses the first that has a key for the account:
- The
UNIFI_API_KEYenvironment variable. Read-only, and it answers for every account. - The operating system keychain: the macOS Keychain, the Secret Service on Linux (GNOME Keyring, KWallet), the Windows Credential Manager.
- A credentials file,
~/.config/unifi-cli/credentials.yaml. unifi-cli creates it readable by you alone and refuses to read it when its permissions are wider.
unifi login writes to the keychain and falls back to the file when the machine has no keychain, or when the keychain doesn't answer within three seconds, which is what a locked or half-configured keyring on a headless Linux box tends to do. When a key is saved to one store, a stale copy in the other is removed. The configuration file never holds a key.
UNIFI_CREDENTIAL_STORE takes the decision out of unifi-cli's hands:
| Value | Stores and looks up keys in |
|---|---|
auto (default) | the keychain, falling back to the file |
keyring | the keychain only |
file | the file only; the keychain is never touched |
UNIFI_CREDENTIAL_STORE=file unifi login --local --address https://192.168.1.1 --pin-certificateSet the variable for later commands too, since it also decides where keys are looked up.
In the keychain, each account is one entry under the service name unifi-cli. A configuration file at another location (UNIFI_CONFIG) gets a service of its own, unifi-cli:<path>, so a demo or test setup can't overwrite the key of a same-named account in your real one.
unifi ctx describe tells you which store answers for a context, and for a key that --sso created also its name and expiry:
$ unifi ctx describe demo --offline
demo ● current ○ not checked
Context
Name demo
Default site Default
Account
Name demo
Type local (API key of the controller, direct connection)
API key stored in the file credential store
Controller
Name demo
Address https://localhost:8443
TLS certificate is not verifiedSign out
unifi logout # the current context
unifi logout lab --yes # a named one, without the confirmation
unifi logout --allSigning out removes the context from the configuration. Its account and controller go too when no other context uses them, together with the stored key and the certificate pinned for the controller. unifi ctx delete cleans up the same way.
Removing a key from your machine doesn't invalidate it at Ubiquiti. What happens next depends on who created the key.
A key that unifi login --sso created can be revoked as part of the sign-out. On a terminal you're asked; scripts pass --revoke-key, or --keep-key to leave it valid without a question. With --yes and neither flag the key is kept. Revoking needs a session with your UI account: unifi-cli uses the one saved at sign-in, and when that has expired it asks for your password again.
$ unifi logout demo-sso --yes --revoke-key
✓ Signed out of the context "demo-sso".
→ Removed the API key of the account "demo-sso" from the credential store.
→ Revoked the API key "unifi-cli (<hostname>)" at Ubiquiti.A key you created yourself is never revoked by unifi-cli. Delete it where you created it if it should stop working.
When it fails
| Message | Likely cause |
|---|---|
| The API key could not be verified with the UniFi Site Manager. | The key was copied incompletely, or it's a local key; local keys need --local. |
| The controller rejected the API key. | The key was deleted or expired on the console. |
| The TLS certificate of ... is not trusted. | Self-signed certificate; see above. |
| The certificate of ... is not trusted: it no longer matches the certificate pinned for it. | The console presents a different certificate than the pinned one; see troubleshooting. |
| The certificate cannot be pinned: it is not valid for the address ... | Use the name the certificate was issued to as the address. |
| The account has 2 consoles, and no terminal is attached to ask which one to use. | Pass --console <name> or --all-consoles. |
The troubleshooting guide covers connection problems in more depth.
