2020-07-14 21:02:41 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/statements/alter/user
2022-04-09 13:29:05 +00:00
sidebar_position: 45
sidebar_label: USER
2022-08-29 16:19:50 +00:00
title: "ALTER USER"
2020-07-14 21:02:41 +00:00
---
Changes ClickHouse user accounts.
Syntax:
``` sql
2024-09-04 09:12:42 +00:00
ALTER USER [IF EXISTS] name1 [RENAME TO new_name |, name2 [,...]]
[ON CLUSTER cluster_name]
2024-09-26 15:30:40 +00:00
[NOT IDENTIFIED | RESET AUTHENTICATION METHODS TO NEW | {IDENTIFIED | ADD IDENTIFIED} {[WITH {plaintext_password | sha256_password | sha256_hash | double_sha1_password | double_sha1_hash}] BY {'password' | 'hash'}} | WITH NO_PASSWORD | {WITH ldap SERVER 'server_name'} | {WITH kerberos [REALM 'realm']} | {WITH ssl_certificate CN 'common_name' | SAN 'TYPE:subject_alt_name'} | {WITH ssh_key BY KEY 'public_key' TYPE 'ssh-rsa|...'} | {WITH http SERVER 'server_name' [SCHEME 'Basic']}
2024-09-26 17:17:45 +00:00
[, {[{plaintext_password | sha256_password | sha256_hash | ...}] BY {'password' | 'hash'}} | {ldap SERVER 'server_name'} | {...} | ... [,...]]]
2021-03-11 20:41:10 +00:00
[[ADD | DROP] HOST {LOCAL | NAME 'name' | REGEXP 'name_regexp' | IP 'address' | LIKE 'pattern'} [,...] | ANY | NONE]
2023-09-13 03:14:02 +00:00
[VALID UNTIL datetime]
2020-07-14 21:02:41 +00:00
[DEFAULT ROLE role [,...] | ALL | ALL EXCEPT role [,...] ]
2021-05-13 20:05:11 +00:00
[GRANTEES {user | role | ANY | NONE} [,...] [EXCEPT {user | role} [,...]]]
2021-03-11 20:41:10 +00:00
[SETTINGS variable [= value] [MIN [=] min_value] [MAX [=] max_value] [READONLY | WRITABLE] | PROFILE 'profile_name'] [,...]
2020-07-14 21:02:41 +00:00
```
2024-05-02 07:00:40 +00:00
To use `ALTER USER` you must have the [ALTER USER ](../../../sql-reference/statements/grant.md#access-management ) privilege.
2020-07-14 21:02:41 +00:00
2022-06-02 10:55:18 +00:00
## GRANTEES Clause
2021-05-07 20:49:15 +00:00
2024-05-02 07:00:40 +00:00
Specifies users or roles which are allowed to receive [privileges ](../../../sql-reference/statements/grant.md#privileges ) from this user on the condition this user has also all required access granted with [GRANT OPTION ](../../../sql-reference/statements/grant.md#granting-privilege-syntax ). Options of the `GRANTEES` clause:
2021-05-07 20:49:15 +00:00
2023-04-19 15:55:29 +00:00
- `user` — Specifies a user this user can grant privileges to.
- `role` — Specifies a role this user can grant privileges to.
- `ANY` — This user can grant privileges to anyone. It's the default setting.
- `NONE` — This user can grant privileges to none.
2021-05-07 20:49:15 +00:00
2021-05-13 21:46:57 +00:00
You can exclude any user or role by using the `EXCEPT` expression. For example, `ALTER USER user1 GRANTEES ANY EXCEPT user2` . It means if `user1` has some privileges granted with `GRANT OPTION` it will be able to grant those privileges to anyone except `user2` .
2021-05-07 20:49:15 +00:00
2022-06-02 10:55:18 +00:00
## Examples
2020-07-14 21:02:41 +00:00
Set assigned roles as default:
``` sql
ALTER USER user DEFAULT ROLE role1, role2
```
If roles aren’ t previously assigned to a user, ClickHouse throws an exception.
Set all the assigned roles to default:
``` sql
ALTER USER user DEFAULT ROLE ALL
```
If a role is assigned to a user in the future, it will become default automatically.
Set all the assigned roles to default, excepting `role1` and `role2` :
``` sql
ALTER USER user DEFAULT ROLE ALL EXCEPT role1, role2
```
2021-05-07 20:49:15 +00:00
2021-05-09 15:50:03 +00:00
Allows the user with `john` account to grant his privileges to the user with `jack` account:
2021-05-07 20:49:15 +00:00
``` sql
ALTER USER john GRANTEES jack;
```
2024-06-29 21:29:05 +00:00
2024-07-25 12:07:13 +00:00
Adds new authentication methods to the user while keeping the existing ones:
2024-06-29 21:29:05 +00:00
``` sql
2024-07-25 12:07:13 +00:00
ALTER USER user1 ADD IDENTIFIED WITH plaintext_password by '1', bcrypt_password by '2', plaintext_password by '3'
2024-06-29 21:29:05 +00:00
```
2024-07-26 17:40:50 +00:00
Notes:
2024-07-29 12:50:54 +00:00
1. Older versions of ClickHouse might not support the syntax of multiple authentication methods. Therefore, if the ClickHouse server contains such users and is downgraded to a version that does not support it, such users will become unusable and some user related operations will be broken. In order to downgrade gracefully, one must set all users to contain a single authentication method prior to downgrading. Alternatively, if the server was downgraded without the proper procedure, the faulty users should be dropped.
2024-07-26 17:40:50 +00:00
2. `no_password` can not co-exist with other authentication methods for security reasons.
2024-07-25 12:07:13 +00:00
Because of that, it is not possible to `ADD` a `no_password` authentication method. The below query will throw an error:
2024-06-29 21:29:05 +00:00
``` sql
2024-07-25 12:07:13 +00:00
ALTER USER user1 ADD IDENTIFIED WITH no_password
2024-06-29 21:29:05 +00:00
```
2024-07-25 12:07:13 +00:00
If you want to drop authentication methods for a user and rely on `no_password` , you must specify in the below replacing form.
Reset authentication methods and adds the ones specified in the query (effect of leading IDENTIFIED without the ADD keyword):
``` sql
ALTER USER user1 IDENTIFIED WITH plaintext_password by '1', bcrypt_password by '2', plaintext_password by '3'
```
Reset authentication methods and keep the most recent added one:
2024-06-29 21:29:05 +00:00
``` sql
2024-07-25 12:07:13 +00:00
ALTER USER user1 RESET AUTHENTICATION METHODS TO NEW
2024-06-29 21:29:05 +00:00
```