# Wandb disable local api key storage

**URL:** <https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955>\
**Category:** W&B Help\
**Tags:** wandb\
**Created:** [August 26, 2023, 6:55pm UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955 "2023-08-26T18:55:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zqbi](https://avatars.discourse-cdn.com/v4/letter/z/45deac/32.png) [@zqbi](https://community.wandb.ai/u/zqbi)\
**Post date:** [August 26, 2023, 6:55pm UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/1 "2023-08-26T18:55:12Z")

</div>

Hi,  
I am using a public computing server with a shared user, I’ve specify my wandb api key in the wandb.init() api call, however, after execution, it will store my api key in ~/.netrc, and overwrite the previous api key (may used by other users). Can I disable this behavior, or specify another file to cache my API key?

---

<div class="post-metadata">

**Author:** ![mohammadbakir](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mohammadbakir](https://community.wandb.ai/u/mohammadbakir)\
**Post date:** [August 31, 2023, 12:40am UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/2 "2023-08-31T00:40:12Z")

</div>

Hi @zqbi , happy to help. There is currently no option to list multiple api keys in a single netrc file. If you were to do this manually, wandb will default to the last listed api key to authenticate the user. The recommended approach for shared machine is:

- set your api key in your environment `os.environ["WANDB_API_KEY"]="<api-key>"`
- set your api key with `wandb.login(key="<api-key>")`

Please let me know if you have any questions.

---

<div class="post-metadata">

**Author:** ![zqbi](https://avatars.discourse-cdn.com/v4/letter/z/45deac/32.png) [@zqbi](https://community.wandb.ai/u/zqbi)\
**Post date:** [September 1, 2023, 4:30am UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/3 "2023-09-01T04:30:47Z")

</div>

Hi @mohammadbakir , thanks for replying.

I’ve tried to use this method, however, although now the wandb system use the API key specified in `wandb.login(<api-key>)` , the private API key is still saved in `~/.netrc`, is there an approach to use the API key only in current session without saving?

---

<div class="post-metadata">

**Author:** ![mohammadbakir](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mohammadbakir](https://community.wandb.ai/u/mohammadbakir)\
**Post date:** [September 5, 2023, 7:30pm UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/4 "2023-09-05T19:30:44Z")

</div>

Hi @zqbi ,

Unfortunately not, my recommendation here is to delete the file at the end of your code

```auto
import os
import wandb

wandb.login(key="<your api key>")
... #Business Logic

file_path = os.path.expanduser("~/.netrc")

# Check if the file exists before attempting to delete it
if os.path.exists(file_path):
    os.remove(file_path)
    print(f"{file_path} has been deleted.")
else:
    print(f"{file_path} does not exist.")

```

---

<div class="post-metadata">

**Author:** ![mohammadbakir](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mohammadbakir](https://community.wandb.ai/u/mohammadbakir)\
**Post date:** [September 8, 2023, 6:43pm UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/5 "2023-09-08T18:43:22Z")

</div>

Hi @zqbi , since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [November 7, 2023, 6:43pm UTC](https://community.wandb.ai/t/wandb-disable-local-api-key-storage/4955/6 "2023-11-07T18:43:23Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
