401 Unauthorized: unauthorized access InfluxDB CLI

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
–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.

I’m sure I’m doing something wrong, but I can’t figure out what :confused:
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

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

1 Like

up to be more visible

you need admin token given when you installed it.

generated tokens do not work with CLI.

1 Like

Is there any way to retrieve the admin token?

Hi everyone,
I unlocked my situation with this solution
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.

1 Like

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

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

  1. create a CLI config
influxdb@develop ~ % influx config create \
  -n config-name \
  -u http://localhost:8086 \
  -p USERNAME:PASSWORD \
  -o MyOrganization
  1. Now use the CLI
influxdb@develop ~ % influx user list
ID			Name
0b0b8f90c305e000	datahub

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!