|
| 1 | +--- |
| 2 | +date: 2025-01-16 |
| 3 | +title: "How to remove the default user" |
| 4 | +description: "Learn how to remove the default user when running ClickHouse Server." |
| 5 | +--- |
| 6 | + |
| 7 | +In this guide, we're going to learn how to remove the `default` user from ClickHouse Server. |
| 8 | + |
| 9 | +We can do this by creating a YAML file (let's call it `remove_default_user.yaml`) that has the following content |
| 10 | + |
| 11 | +```yaml |
| 12 | +users: |
| 13 | + default: |
| 14 | + "@remove": remove |
| 15 | +``` |
| 16 | +
|
| 17 | +The location of this file depends on how we have ClickHouse installed. |
| 18 | +
|
| 19 | +## Running the executable directly |
| 20 | +
|
| 21 | +If we're running the ClickHouse directly (`clickhouse server`), we need to put the file under the `config.d` directory. |
| 22 | + |
| 23 | +When we run ClickHouse Server: |
| 24 | + |
| 25 | +``` |
| 26 | +clickhouse server |
| 27 | +``` |
| 28 | + |
| 29 | +We'll see the following line in the logs: |
| 30 | + |
| 31 | +``` |
| 32 | +{} <Debug> ConfigProcessor: Merging configuration file 'config.d/remove_default_user.yaml'. |
| 33 | +``` |
| 34 | + |
| 35 | +And we'll be unable to connect using `clickhouse client`: |
| 36 | + |
| 37 | +``` |
| 38 | +ClickHouse client version 24.11.1.2557 (official build). |
| 39 | +Connecting to localhost:9000 as user default. |
| 40 | +Password for user (default): |
| 41 | +Connecting to localhost:9000 as user default. |
| 42 | +Code: 516. DB::Exception: Received from localhost:9000. DB::Exception: default: Authentication failed: password is incorrect, or there is no user with such name. |
| 43 | +``` |
| 44 | + |
| 45 | +## Docker or installed |
| 46 | + |
| 47 | +If we're running ClickHouse via Docker or have it installed on our machine, we need to put the file under the `/etc/clickhouse-server/users.d` directory instead. |
| 48 | + |
| 49 | +So if we're running with Docker, we can mount the `config.d` directory that we created earlier to `/etc/clickhouse-server/users.d`: |
| 50 | + |
| 51 | +```bash |
| 52 | +docker run \ |
| 53 | + -v ./config.d:/etc/clickhouse-server/users.d \ |
| 54 | + -p 8123:8123 -p9000:9000 \ |
| 55 | + clickhouse/clickhouse-server:24.12 |
| 56 | +``` |
| 57 | + |
| 58 | +``` |
| 59 | +Merging configuration file '/etc/clickhouse-server/config.d/docker_related_config.xml'. |
| 60 | +Logging trace to /var/log/clickhouse-server/clickhouse-server.log |
| 61 | +Logging errors to /var/log/clickhouse-server/clickhouse-server.err.log |
| 62 | +``` |
| 63 | +
|
| 64 | +We can then search the server logs to check that it gets picked up: |
| 65 | +
|
| 66 | +```bash |
| 67 | +docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Command}}" |
| 68 | +``` |
| 69 | + |
| 70 | +```text |
| 71 | +CONTAINER ID IMAGE NAMES COMMAND |
| 72 | +383e8ed89431 clickhouse/clickhouse-server:24.12 trusting_rosalind "/entrypoint.sh" |
| 73 | +``` |
| 74 | + |
| 75 | +``` |
| 76 | +docker exec -it trusting_rosalind grep "users\.d" /var/log/clickhouse-server/clickhouse-server.log |
| 77 | +``` |
| 78 | + |
| 79 | +We should see the following line: |
| 80 | + |
| 81 | +```text |
| 82 | +{} <Debug> ConfigProcessor: Merging configuration file '/etc/clickhouse-server/users.d/remove_default_user.yaml'. |
| 83 | +``` |
0 commit comments