# How to log out all members?

**URL:** <https://meta.discourse.org/t/how-to-log-out-all-members/63404>\
**Category:** Support\
**Created:** [2017年五月25日 23:10 UTC](https://meta.discourse.org/t/how-to-log-out-all-members/63404 "2017-05-25T23:10:59Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [2017年五月27日 18:42 UTC](https://meta.discourse.org/t/how-to-log-out-all-members/63404/4 "2017-05-27T18:42:08Z")

</div>

This [should be enough](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670/17) to log out all users, with the possibility of exempting some users:

```ruby
protected_users = ["system", "codinghorror"] # do not process these users

# get all users that should be logged out
affected_users = User.all.select { |u| !(protected_users.include? u.username) }

affected_users.each { |u|
        u.user_auth_tokens.destroy_all
        u.logged_out
};

```

This needs to be run within Rails – pasting it into a rails console (`./launcher enter app`, `rails c`) should be enough.

**Better safe than sorry: Always have a backup ready before going near the Rails console.**

---

_[View the full topic](https://meta.discourse.org/t/how-to-log-out-all-members/63404)._
