The `huggingface-cli login` command is used to authenticate your Hugging Face CLI with your Hugging Face account. This allows you to interact with the Hugging Face Hub, including downloading private models/datasets, uploading models/datasets, and managing your repositories.
huggingface-cli loginWhen you run `huggingface-cli login`, the CLI will prompt you to enter your Hugging Face token. This token acts as your password for programmatic access to the Hugging Face Hub.
$ huggingface-cli login
_| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_|_|
_| _| _| _| _| _| _| _|_| _| _|
_|_|_|_| _| _| _| _|_| _| _|_| _| _| _|_| _| _|_|_|
_| _| _| _| _| _| _| _| _| _| _|_|_| _|
_| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_|_|
To login, `huggingface_hub` needs a token recognizing your identity.
To get one, you can go to https://huggingface.co/settings/tokens.
...
Token:1. **Generate a Token**: Before running `huggingface-cli login`, you need to generate a Hugging Face Access Token. You can do this by visiting your Hugging Face settings page: `https://huggingface.co/settings/tokens`. Click on "New token", give it a name (e.g., "CLI Access"), and choose the appropriate "Role". For most common tasks (downloading and uploading), a `write` role is recommended. For read-only access, a `read` role suffices.
2. **Enter the Token**: Copy the generated token and paste it into your terminal when prompted by `huggingface-cli login`.
3. **Authentication Success**: Upon successful entry, the CLI will store your token securely on your machine (typically in `~/.cache/huggingface/token` or `~/.cache/huggingface/token` on Linux/macOS, or an equivalent path on Windows). You will see a confirmation message:
Token is valid (permission: write).
Your token has been saved to /home/user/.cache/huggingface/tokenWhile `huggingface-cli login` is the primary method, you can also authenticate using environment variables:
* **`HF_TOKEN`**: Set this environment variable to your Hugging Face token. The CLI and `huggingface_hub` library will automatically pick it up.
export HF_TOKEN="hf_YOUR_SECRET_TOKEN"
# Then you can run other commands without explicitly logging in
huggingface-cli whoamiYou can verify if you are logged in and with which user/organization using the `whoami` command:
$ huggingface-cli whoami
user: your_username
orgs: your_org_name (if any)To remove your stored token and log out, use the `logout` command:
huggingface-cli logout* Your token is sensitive information. Treat it like a password. Do not share it publicly or commit it to version control.
* If you suspect your token has been compromised, revoke it immediately from your Hugging Face settings page and generate a new one.