{"record":{"id":"dacbd8eaab542212","repo":"atuinsh/atuin","slug":"no-key-provided-and-no-existing-key-file-found-please-use","errorCode":null,"errorMessage":"No key provided and no existing key file found. Please use 'atuin key' on your other machine, or recover your key from a backup","messagePattern":"No key provided and no existing key file found\\. Please use 'atuin key' on your other machine, or recover your key from a backup","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/atuin/src/command/client/account/login.rs","lineNumber":219,"sourceCode":"        let interactive = self.interactive();\n        let mut flag_key = self.key.clone();\n\n        loop {\n            let key = match flag_key.take() {\n                Some(key) => key,\n                None => match read_user_input(\"encryption key [blank to use existing key file]\") {\n                    Some(key) => key,\n                    // Stdin is exhausted, so re-prompting would spin forever.\n                    None => bail!(\"No encryption key provided\"),\n                },\n            };\n\n            if key.is_empty() {\n                if !key_path.exists() {\n                    let msg = \"No key provided and no existing key file found. Please use 'atuin \\\n                               key' on your other machine, or recover your key from a backup\";\n                    if !interactive {\n                        bail!(msg);\n                    }\n                    println!(\"\\n{msg}\\n\");\n                    continue;\n                }\n\n                paseto_v4::Key::try_load_from_path(key_path).context(format!(\n                    \"The key in existing key file at '{}' is invalid\",\n                    key_path.to_string_lossy()\n                ))?;\n\n                return Ok(());\n            }\n\n            // The key may be EITHER base64 or a bip39 mnemonic.\n            match paseto_v4::Key::try_from_mnemonic(&key) {\n                Ok(key) => return store_key(settings, store, &key).await,\n                Err(err) if interactive => println!(\"\\n{err}. Please try again.\\n\"),\n                Err(err) => return Err(err.into()),","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin/src/command/client/account/login.rs#L201-L237","documentation":"When logging in, if the user submits an empty encryption key, atuin falls back to an existing key file. If that key file does not exist and the session is non-interactive, it bails with this message telling the user to recover the key with `atuin key` from the original machine or a backup — without the key, history cannot be decrypted.","triggerScenarios":"Running `atuin login` (with or without --key '') on a machine with no `~/.local/share/atuin/key` file, in a non-interactive context so the re-prompt loop is impossible; also fresh containers/second machines.","commonSituations":"Setting up a new laptop/VM without copying the key file; CI environments without an interactive prompt; lost key file after reinstalling the OS; ATUIN_DATA_DIR pointing somewhere the key was never stored.","solutions":["Run `atuin key` on the original machine and pass it here: `atuin login --key <key>`","Copy the key file (`~/.local/share/atuin/key`) from the existing machine to the new one, then login with an empty key to reuse it","Restore the key from your backup of the atuin data directory","If truly interactive, re-run in a terminal — the message is only fatal when `interactive` is false"],"exampleFix":"// before: non-interactive, no key, no key file\natuin login < /dev/null\n\n// after: fetch key from existing machine, then\nOLD: atuin key   # copy output\nNEW: atuin login --key \"<key-from-old-machine>\"","handlingStrategy":"fallback","validationCode":"KEY_FILE=\"$HOME/.local/share/atuin/key\"\nif [ ! -f \"$KEY_FILE\" ] && [ -z \"$ATUIN_KEY\" ]; then\n  echo 'Fetch the key with `atuin key` on your original machine first' >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":"if ! atuin login --key \"$ATUIN_KEY\"; then\n  echo \"Login failed — recover the key from the original machine or backup\" >&2\nfi","preventionTips":["Back up ~/.local/share/atuin/key as soon as the key is created","Copy the key file to new machines before first login","Keep the key in a password manager for recovery","Re-run login in an interactive terminal to get the retry prompt instead of a hard bail"],"tags":["cli","encryption","key","recovery"],"backgroundTag":"missing-credentials","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}