Using the cargo login Command

Using the auth token generated in Create Auth Token, you can use the cargo login command to save the token in ~/.cargo/credentials for future reuse.

Note: please be aware the token will be saved in plain text (600/rw------- mode) in ~/.cargo/credentials.

To save the token using cargo login:

$ cargo login \
--registry my-crate-registry \
dOvx04Jm4lYGw=

In the above command, my-crate-registry should match the name given to the registry in the [registries] configuration entry.

$ cargo login --help
cargo-login 
Save an api token from the registry locally. If token is not specified, it will be
read from stdin.

USAGE:
  cargo login [OPTIONS] [token]

ARGS:
  <token>    

OPTIONS:
      --registry <REGISTRY>    Registry to use
      # ...

Successful login will produce a message like this:

$ TOKEN="x8P1UUELcY6SxRA3Ylsjlkjsdfoiew0239Lh7Gth5qrI46a3mZ47cjA0wDU+9cNmJMQ="
$ cargo login \
--registry my-crate-registry \
${TOKEN}

Updating `my-crate-registry` index
Login token for `my-crate-registry` saved