> For the complete documentation index, see [llms.txt](https://blog.egonzalez.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.egonzalez.org/openstack/index/list-all-tenants-belonging-an-user.md).

# List all tenants belonging an user

```
#!/bin/bash
   echo -n "Username : " ; read usercheck
   for userid in $(keystone user-list | grep -w $usercheck | awk '{print$2}')
       do
       for tenant in $(keystone tenant-list | awk 'NR>3 && /^|/ {print$2}')
       do
           for tenantid in $(keystone user-role-list --user $userid --tenant $tenant | awk 'NR>3 && /^|/ {print$8}')
           do
               keystone tenant-list | grep $tenantid | awk '{print$4}'
           done
       done
   done
```

Also you can run all in a simple cmd line

```
echo -n "user name "; read usercheck; for userid in $(keystone user-list | grep $usercheck | awk '{print$2}'); do echo $userid | for tenant in $(keystone tenant-list | awk 'NR>3 && /^|/ {print$2}'); do echo $tenant | for tenantid in $(keystone user-role-list --user $userid --tenant $tenant | awk 'NR>3 && /^|/ {print$8}'); do keystone tenant-list | grep $tenantid | awk '{print$4}'; done ; done ; done
```

If you are a developer, probably you need to list all tenants in a HTTP request, for this purpose you can use the REST API to the port 5000 of keystone

```
curl -i -X GET http://KEYSTONEIP:5000/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: USERTOKEN"
```

I have saved the user token in a OS\_VARIABLE called OS\_TOKEN, if you don't do that, you should input all the token in the HTTP request.

```
curl -i -X GET http://192.168.1.11:5000/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: $OS_TOKEN"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.egonzalez.org/openstack/index/list-all-tenants-belonging-an-user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
