cargo-login
Authenticate with a crates.io registry
TLDR
Add an API token to the local credential storage (located in $CARGO_HOME/credentials.toml)
Use the specified registry (registry names can be defined in the configuration - the default is
SYNOPSIS
cargo login [OPTIONS] [<REGISTRY>]
PARAMETERS
--registry <REGISTRY>
Registry name to authenticate with (defaults to crates-io).
-h, --help
Print help information.
-V, --version
Print version information.
DESCRIPTION
cargo login authenticates the user with a Cargo package registry, such as the default crates.io, by securely storing a personal API token.
Upon execution, it prompts for the token interactively unless provided via stdin (e.g., via echo $TOKEN | cargo login). The token grants permissions like publishing crates or accessing private registries.
The credential is saved in a platform-appropriate store: ~/.cargo/credentials.toml on Unix-like systems (with chmod 600 for security), or Windows Credential Manager/MacOS Keychain on other platforms.
Use a specific registry with the positional argument or --registry flag. Providing - as registry skips authentication.
This command is essential for developers publishing Rust crates, ensuring authenticated API interactions without repeated token entry. Tokens can be revoked or regenerated on registry dashboards.
CAVEATS
API tokens are sensitive; never commit them to version control or share publicly.
Ensure ~/.cargo/credentials.toml has restrictive permissions (600). Use cargo logout to revoke.
OBTAINING API TOKEN
Generate at crates.io/settings/tokens (login required).
Scoped tokens recommended for security.
NON-INTERACTIVE USAGE
echo 'your_token_here' | cargo login for scripts/CI.
HISTORY
Introduced in Cargo 0.1 (2014) alongside initial Rust package registry support.
Enhanced in later versions for secure credential storage and multiple registry handling.
SEE ALSO
cargo-logout(1), cargo-publish(1), cargo(1)


