# Delete user from discourse-docker using ssh

**URL:** https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820
**Category:** Support
**Created:** [January 12, 2016, 12:57pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820 "2016-01-12T12:57:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ninetailz](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Ninetailz](https://meta.discourse.org/u/Ninetailz)
#### Post date: [January 12, 2016, 12:57pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/1 "2016-01-12T12:57:28Z")

</div>

Hello,

How do you remove user by using

```plaintext
./launcher enter app
```

and deleting the user by rake?  
Just like you create admin with

```plaintext
rake admin:create
```

Is there a way to delete user like that?

Thanks,  
NInetailz

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 12, 2016, 3:01pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/2 "2016-01-12T15:01:15Z")

</div>

As you said, you can enter the container with

```shell
./launcher enter app

```

Then, you will need to launch the [rails console](http://guides.rubyonrails.org/command_line.html#rails-console) with

```shell
rails c

```

Once you’re in the rails console, you can delete a user with

```ruby
User.find_by(username: "foobar").destroy

```

---

<div class="post-metadata">

### Author: ![Ninetailz](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Ninetailz](https://meta.discourse.org/u/Ninetailz)
#### Post date: [January 12, 2016, 9:08pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/3 "2016-01-12T21:08:41Z")

</div>

So i did that and it did removed the user but it showed this (END) line when i kept pressing enter and i closed it by ctrl+z. Is that the right way to close rails c? something telling me its not ..

> root@xxx:~# cd /var/xxx/  
> root@xxx:/var/xxx# ./launcher enter app  
> root@xxx-app:/# rails c  
> [1] pry(main)\> User.find\_by(username: “anon61470549”).destroy  
> =\> #\<User:0x007fc7283af178  
> id: -2,  
> username: “anon61470549”,  
> created\_at: Thu, 07 Jan 2016 01:46:38 UTC +00:00,  
> updated\_at: Tue, 12 Jan 2016 03:00:37 UTC +00:00,  
> name: nil,  
> seen\_notification\_id: 0,  
> last\_posted\_at: nil,  
> email: “[anon61470549@example.com](mailto:anon61470549@example.com)”,  
> password\_hash:  
> “xxx”,  
> salt: “xx”,  
> active: false,  
> username\_lower: “anon61470549”,  
> auth\_token: nil,  
> last\_seen\_at: nil,  
> admin: false,  
> last\_emailed\_at: nil,  
> email\_digests: false,  
> trust\_level: 0,  
> email\_private\_messages: false,  
> email\_direct: false,  
> approved: false,  
> approved\_by\_id: nil,  
> approved\_at: nil,  
> digest\_after\_days: 7,  
> previous\_visit\_at: nil,  
> suspended\_at: nil,  
> suspended\_till: nil,  
> date\_of\_birth: nil,  
> auto\_track\_topics\_after\_msecs: 240000,  
> views: 0,  
> flag\_level: 0,  
> ip\_address: nil,  
> new\_topic\_duration\_minutes: 2880,  
> external\_links\_in\_new\_tab: false,  
> enable\_quoting: true,  
> moderator: false,  
> blocked: false,  
> dynamic\_favicon: false,  
> title: nil,  
> uploaded\_avatar\_id: nil,  
> email\_always: false,  
> mailing\_list\_mode: false,  
> locale: nil,  
> primary\_group\_id: nil,  
> registration\_ip\_address: nil,  
> last\_redirected\_to\_top\_at: nil,  
> disable\_jump\_reply: false,  
> edit\_history\_public: true,  
> trust\_level\_locked: false,  
> staged: false,  
> automatically\_unpin\_topics: true\>

> [1]+ Stopped rails c

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 12, 2016, 9:10pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/4 "2016-01-12T21:10:47Z")

</div>

> [@Ninetailz](#):
>
> i closed it by ctrl+z. Is that the right way to close rails c? something

No that is not the correct way… type:

`exit` enter

twice.

---

<div class="post-metadata">

### Author: ![yuquailon](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@yuquailon](https://meta.discourse.org/u/yuquailon)
#### Post date: [January 12, 2016, 9:46pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/5 "2016-01-12T21:46:09Z")

</div>

Hi,

I’ve tried the way @zogstrip told. The user is no more on the discourse yet I got internal server error when trying to open all of the topics that the user posted in.

The following lines are from production.log and it is the only log that I could fetch so far. What is going wrong?

```
Started GET "/t/bilginin-tamamina-sahip-olmadiginizda-fikir-sahibi-olmadan-once-yapmaniz-gereken-3-sey/10594" for 80.5.152.180 at 2016-01-12 21:36:57 +0000
Processing by TopicsController#show as HTML
  Parameters: {"slug"=>"bilginin-tamamina-sahip-olmadiginizda-fikir-sahibi-olmadan-once-yapmaniz-gereken-3-sey", "topic_id"=>"10594"}
Completed 500 Internal Server Error in 170ms (ActiveRecord: 23.8ms)
NoMethodError (undefined method ``id`` for nil:NilClass)
/var/www/discourse/app/serializers/topic_post_count_serializer.rb:6:in ``id'

```

**UPDATE:**  
The user’s posts are still on the posts table and the error is most likely because of that the user data  
of the post could not be found. Well, deleting posts of the user is just a simple query and I guess it is going to solve this but sanitizing all the data (post, like counts etc.) would take some time to achieve. Is there any sort of script to delete (or anonymize) all post data associated with a specific user (or user\_id)?

---

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [May 24, 2018, 3:49pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/6 "2018-05-24T15:49:22Z")

</div>

> [@zogstrip](#):
>
> you can delete a user with
> 
> ```plaintext
> User.find_by(username: "foobar").destroy
> 
> ```

What would the syntax be to do this by user id?

```plaintext
User.find_by(id: "foobar").destroy

```

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [May 24, 2018, 3:50pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/7 "2018-05-24T15:50:38Z")

</div>

```ruby
User.find_by(id: 1234).destroy

```

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/delete-user-from-discourse-docker-using-ssh/37820/8 "2024-06-08T12:37:25Z")

</div>

This topic was automatically closed after 3069 days. New replies are no longer allowed.
