# Bitwarden CLI: You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out

**URL:** <https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885>\
**Category:** Password Manager\
**Created:** [January 10, 2022, 4:35pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885 "2022-01-10T16:35:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kpiris](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/kpiris/32/14822_2.png) [@kpiris](https://community.bitwarden.com/u/kpiris)\
**Post date:** [January 10, 2022, 4:35pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/1 "2022-01-10T16:35:19Z")

</div>

Hi,

I’ve been using Bitwarden CLI (on linux) since a couple of weeks. It works great and It’s a great piece of software, thanks for it!

There’s one little thing that I’ve been unable to grasp: I’m using a Session Key that I use with the BW\_SESSION environment variable.

When I issue a **bw lock** it always gives me this message:

> You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.

And I’m, effectively, logged out.

What does that mean? Is there any recommended way to lock the CLI session? (pearhaps there’s something that I don’t fully undestand yet -I’m fairly new to Bitwarden-).

I’ve been searching about this but I’ve not been able to find anything useful to me. This “[Key Connector](https://bitwarden.com/help/article/about-key-connector/)” is supposed to be about _SSO Login_, but I’m logging in with master password+second step auth (or with Api Key, which I also tried out).

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dh024](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/dh024/32/17854_2.png) [@dh024](https://community.bitwarden.com/u/dh024)\
**Post date:** [January 10, 2022, 4:50pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/2 "2022-01-10T16:50:14Z")

</div>

If you have saved your session key to an environment variable, this key is used to decrypt your vault to access items within - this happens automatically on any bw command. To lock your vault, you would need to delete that environment variable first.

e.g., on Linux:  
` unset BW_SESSION `

e.g., on Windows:  
` BW_SESSION= `

Terminating your shell session and restarting a new one will have the same effect, assuming that you exported the BW\_SESSION variable within a session (i.e., you did not add it to your shell profile).

Not sure why it refers to the “Key Connector” though. I am pretty sure it is referring to a session key.

---

<div class="post-metadata">

**Author:** ![kpiris](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/kpiris/32/14822_2.png) [@kpiris](https://community.bitwarden.com/u/kpiris)\
**Post date:** [January 10, 2022, 4:56pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/3 "2022-01-10T16:56:13Z")

</div>

> [@dh024](#):
>
> To lock your vault, you would need to delete that environment variable first

That is what I suspected, but wasn’t sure.

> [@dh024](#):
>
> Not sure why it refers to the “Key Connector” though. I am pretty sure it is referring to a session key.

OK, that makes more sense to me now.

Thank you!!

---

<div class="post-metadata">

**Author:** ![kpiris](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/kpiris/32/14822_2.png) [@kpiris](https://community.bitwarden.com/u/kpiris)\
**Post date:** [January 10, 2022, 5:23pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/4 "2022-01-10T17:23:16Z")

</div>

Now that I think a bit more about this (and, please, excuse me if what I’m about to say doesn’t make any sense).

Unsetting the BW\_SESSION variable indeed does “lock” the vault as it “forgets” the key which encrypts the data contained in it.

However, the value of that BW\_SESSION variable could end up saved somewhere in the system (if one decides to save it in a shell profile or it gets (accidentally or not) written in a command history file, for example.

I think it would be useful if **bw lock** rotated the Session Key (encrypting the vault with this new one) and this new Session Key wasn’t passed in any way to the user.

This way, you would end with a still locked vault, but with a key that hasn’t been able to be saved anywhere in the system.

And when you needed to unlock the vault to access it, a **bw unlock** would generate a new Session Key without the need to provide the second auth step (which is the point of locking the vault instead of logging it out).

Does this make sense?

Thanks again!

---

<div class="post-metadata">

**Author:** ![dh024](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/dh024/32/17854_2.png) [@dh024](https://community.bitwarden.com/u/dh024)\
**Post date:** [January 10, 2022, 6:52pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/5 "2022-01-10T18:52:35Z")

</div>

I believe this is the behaviour if you manually lock the vault with the command `bw lock` after you have removed the BW\_SESSION variable. Try this to see (it works for me):

```auto
bw unlock
export BW_SESSION="xxxxxxxxxxxxxxxxxx" #use your session key here
bw list folders #should not prompt for authentication
unset BW_SESSION
bw lock
export BW_SESSION="xxxxxxxxxxxxxxxxxx" #use the same session key you used above
bw list folders # this time, you should be prompted to authenticate, meaning sesion key has expired

```

---

<div class="post-metadata">

**Author:** ![kpiris](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/kpiris/32/14822_2.png) [@kpiris](https://community.bitwarden.com/u/kpiris)\
**Post date:** [January 10, 2022, 7:20pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/6 "2022-01-10T19:20:11Z")

</div>

> [@dh024](#):
>
> I believe this is the behaviour if you manually lock the vault with the command `bw lock` after you have removed the BW\_SESSION variable. Try this to see (it works for me):

It does not for me, it logs me out with the message in the OP:

```auto
$ echo $BW_SESSION

$ bw status | jq -r '.status'
locked
$ bw lock
You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.

```

_bw lock_ **always** logs me out with that message. Regardless of the value of BW\_SESSION.

By the way I’m using 1.20.0 version (which, I believe, is the latest one):

```auto
$ bw -v
1.20.0
$ bw update
No update available.

```

---

<div class="post-metadata">

**Author:** ![dh024](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/dh024/32/17854_2.png) [@dh024](https://community.bitwarden.com/u/dh024)\
**Post date:** [January 10, 2022, 8:55pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/7 "2022-01-10T20:55:52Z")

</div>

Interesting - for me, if I remove the BW\_SESSION variable, I of course get prompted for authentication, but if I later set the session variable to the old key, it works just fine. But if I lock the vault (with bw lock), the key no longer works. So it seems that it is necessary to execute the lock command to force the key to expire.

I did notice that I am on version 1.18 of the CLI. I won’t get a chance to do it right away, but tonight I will update to the same version as you and see if I get the same error. And admittedly, I was running this on my mac, so maybe I will try it on my linux box as well. Cheers!

---

<div class="post-metadata">

**Author:** ![dh024](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/dh024/32/17854_2.png) [@dh024](https://community.bitwarden.com/u/dh024)\
**Post date:** [January 10, 2022, 11:07pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/8 "2022-01-10T23:07:35Z")

</div>

I gave it a shot on bw version 1.20, and now I get the same error as you @kpiris. So it may be a bug.

I was about to submit a bug report to Bitwarden, but I see someone beat me to it:

> <https://github.com/bitwarden/cli/issues/439>
>
> \<!--
> Please do not submit feature requests. The \[Community Forums\]\[1\] has a
> se…ction for submitting, voting for, and discussing product feature requests.
> \[1\]: http://community.bitwarden.com
> \--\>
> 
> \## Describe the Bug
> Starting with cli version 1.20, trying to lock the vault results in this message and a logout:
> \`\`\`
> You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.
> \`\`\`
> 
> 
> \## Steps To Reproduce
> 
> Login via a password and 2fa:
> \`\`\`
> $ bw login $EMAIL
> ? Master password: \[hidden\]
> ? Two-step login code: 
> 
> You are logged in!
> 
> To unlock your vault, set your session key to the \`BW\_SESSION\` environment variable. ex:
> $ export BW\_SESSION="..."
> \> $env:BW\_SESSION=".."
> 
> You can also pass the session key to any command with the \`--session\` option. ex:
> $ bw list items --session ...
> \`\`\`
> Then try to lock:
> \`\`\`
> $ bw lock
> You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.
> $ bw login --check
> You are not logged in.
> \`\`\`
> 
> \## Expected Result
> Since I don't use Key Connect, I expect to get the same result as in version 1.19:
> \`\`\`Your vault is locked.\`\`\`
> 
> \## Actual Result
> \`\`\`
> You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.
> \`\`\`
> 
> \## Environment
> 
> \- Operating system: macOS Monterey
> \- Shell: zsh
> \- Build Version (run \`bw --version\`): 1.20.0

---

<div class="post-metadata">

**Author:** ![samba2](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/samba2/32/15139_2.png) [@samba2](https://community.bitwarden.com/u/samba2)\
**Post date:** [January 11, 2022, 8:52am UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/9 "2022-01-11T08:52:34Z")

</div>

just want to confirm that I am facing the same issue (@dh024: I will also add to your bug report).

FYI: This used to work for me. I logged in once (master password + 2 factor in my case) and then this script only asked for the master password to unlock:

```auto
#!/bin/bash
MY_ITEM_ID=42424242-4242......

export BW_SESSION=$(bw unlock --raw)
VPN_PW=$(bw get password $MY_ITEM_ID)
bw lock

# do something with VPN_PW

```

When executing this on 1.20.0 then the call to `bw lock` logs me out with the mentioned error message:  
`You cannot lock your vault because you are using Key Connector. To protect your vault, you have been logged out.`  
This in turn leads to my script not functioning as expected anymore 😉

---

<div class="post-metadata">

**Author:** ![Nail1684](https://sea1.discourse-cdn.com/flex001/user_avatar/community.bitwarden.com/nail1684/32/47626_2.png) [@Nail1684](https://community.bitwarden.com/u/Nail1684)\
**Post date:** [January 22, 2026, 11:37pm UTC](https://community.bitwarden.com/t/bitwarden-cli-you-cannot-lock-your-vault-because-you-are-using-key-connector-to-protect-your-vault-you-have-been-logged-out/36885/10 "2026-01-22T23:37:06Z")

</div>

Closed on January 22, 2026, 11:37pm UTC


