# 401 Unauthorized: unauthorized access InfluxDB CLI

**URL:** <https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237>\
**Category:** InfluxDB 2\
**Created:** [January 19, 2023, 3:43pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237 "2023-01-19T15:43:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ATeam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ateam/32/11392_2.png) [@ATeam](https://community.influxdata.com/u/ATeam)\
**Post date:** [January 19, 2023, 3:43pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/1 "2023-01-19T15:43:51Z")

</div>

Hi all,  
I have an influxDB installation with UI on windows  
Now I’m trying to run CLI commands on the same instance.  
So, I downloaded the influx CLI and placed it in the same folder as Influxd.  
Next, I followed this guide to create a configuration file by filling in the parameters as follows:  
–config-name, I entered the name “login”  
–host-url, “[http://localhost:8086](http://localhost:8086)”  
–org the organization, used by my user in the UI  
–token, I generated an API token in the “API TOKENS” page setting it as “All Acces”  
–active, to make it active

But now whatever command I run the message that is shown is the following.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/5/5de400a8b53cd0cb73d07ee982858bd93bcbbe97.png)

I’m sure I’m doing something wrong, but I can’t figure out what 😕  
Is there anyone who has been in such a situation or who knows how to help me?

influxDB v2.5.1 (git: 5b6fdbf05d) build\_date: 2022-11-02T18:06:29Z  
influx CLI v2.5.0 (git: 3285a03) build\_date: 2022-11-01T16:32:06Z

---

<div class="post-metadata">

**Author:** ![Greg\_Lions](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/greg_lions/32/3393_2.png) [@Greg\_Lions](https://community.influxdata.com/u/Greg_Lions)\
**Post date:** [February 11, 2023, 7:30am UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/2 "2023-02-11T07:30:02Z")

</div>

I think im a “me too” … starting to really regret moving to v2

---

<div class="post-metadata">

**Author:** ![ATeam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ateam/32/11392_2.png) [@ATeam](https://community.influxdata.com/u/ATeam)\
**Post date:** [February 24, 2023, 3:40pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/3 "2023-02-24T15:40:43Z")

</div>

up to be more visible

---

<div class="post-metadata">

**Author:** ![dudu7731](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/dudu7731/32/12812_2.png) [@dudu7731](https://community.influxdata.com/u/dudu7731)\
**Post date:** [March 2, 2023, 5:00pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/4 "2023-03-02T17:00:17Z")

</div>

you need admin token given when you installed it.

generated tokens do not work with CLI.

---

<div class="post-metadata">

**Author:** ![ATeam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ateam/32/11392_2.png) [@ATeam](https://community.influxdata.com/u/ATeam)\
**Post date:** [March 16, 2023, 9:05am UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/5 "2023-03-16T09:05:26Z")

</div>

Is there any way to retrieve the admin token?

---

<div class="post-metadata">

**Author:** ![ATeam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ateam/32/11392_2.png) [@ATeam](https://community.influxdata.com/u/ATeam)\
**Post date:** [March 16, 2023, 4:47pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/6 "2023-03-16T16:47:55Z")

</div>

Hi everyone,  
I unlocked my situation with this [solution](https://docs.influxdata.com/influxdb/v2.4/tools/influx-cli/?t=Windows#authenticate-with-a-username-and-password)  
Instead of logging in with a token I used the credentials I usually use in the GUI.  
I know it’s not really a solution, but it worked out for me.

---

<div class="post-metadata">

**Author:** ![dudu7731](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/dudu7731/32/12812_2.png) [@dudu7731](https://community.influxdata.com/u/dudu7731)\
**Post date:** [March 26, 2023, 7:10pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/7 "2023-03-26T19:10:12Z")

</div>

i had to reinstall (make a backup of data via files before) and now i backup all my token everyday via CLI

---

<div class="post-metadata">

**Author:** ![sweihub](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/sweihub/32/13377_2.png) [@sweihub](https://community.influxdata.com/u/sweihub)\
**Post date:** [May 5, 2023, 12:37pm UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/9 "2023-05-05T12:37:30Z")

</div>

How to login with the the influx 2 command line? The document is confusing, now just figured it out

> **[Install and use the influx CLI | InfluxDB Cloud (TSM) Documentation](https://docs.influxdata.com/influxdb/v2.7/tools/influx-cli/#set-up-the-influx-cli)**
>
> Use the influx command line interface to interact with and manage InfluxDB Cloud.

1. create a CLI config

```sh
influxdb@develop ~ % influx config create \
  -n config-name \
  -u http://localhost:8086 \
  -p USERNAME:PASSWORD \
  -o MyOrganization

```

1. Now use the CLI

```sh
influxdb@develop ~ % influx user list
ID Name
0b0b8f90c305e000	datahub

```

---

<div class="post-metadata">

**Author:** ![Tung](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tung/32/16691_2.png) [@Tung](https://community.influxdata.com/u/Tung)\
**Post date:** [October 15, 2024, 1:42am UTC](https://community.influxdata.com/t/401-unauthorized-unauthorized-access-influxdb-cli/28237/10 "2024-10-15T01:42:44Z")

</div>

Here is the easier solution as I was experiencing the same 401 error when invoking “influx” on the CLI, I found a better way to change the Token value. The “influx” cmd is tied to the original token as mentioned above, but if you created a new operator || all-access token or deleted the original token, here is the approach to fix it.

If you are running Docker,

- access your influx container \> $sudo docker exec -it CONTAINERID /bin/bash
- you are now root in your container
- check if you have nano installed or some editor, if not $apt-get update && apt-get nano
- $cd /etc/influxdb2
- this is where you will find the influxdb config file called “influx-configs”
- now, $influx auth list
- this will reveal the Token for all the respective users, find the User who has an Operator || All-Access Token, and copy it (I did it with an Operator Token, I think All-Access should work too, as long as you use the -organization flag value that All Access token has access to)
- then $nano influx-configs, make sure you are in the directory of /etc/influxdb2, if not add path to the nano command
- you will see the original token in the token key/value pair in the influx-configs file
- shift+ins to paste the copied Operator token, and remove the original Token value, save file
- invoke some $influx command, and you should not see the 401 error anymore

This removes the need to reinstall or spin up a new Docker container for influx

p/s: if you are not using Docker, just locate go directly to /etc/influxdb2 on your machine or vm with the same steps

Hope this helps!
