默认密码
clickhouse
安装好之后,系统默认的登录账号密码是 /etc/clickhouse-server/users.d/default-password.xml
文件中配置的,默认密码是 SHA256加密算法生成,由 password_sha256_hex
标签定义,所以不输入密码时会发生如下报错:
- ClickHouse client version 22.8.4.7 (official build).
- Connecting to localhost:9000 as user default.
-
- If you have installed ClickHouse and forgot password you can reset it in the configuration file.
- The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml
- and deleting this file will reset the password.
- See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed.
-
- Code: 516. DB::Exception: Received from localhost:9000. DB::Exception: default: Authentication failed: password is incorrect or there is no user with such name. (AUTHENTICATION_FAILED)
这时候我们只需要把 /etc/clickhouse-server/users.d/default-password.xml
文件删除掉或者重命名,之后只在 /etc/clickhouse-server/user.xml
文件中修改用户配置。
- cd /etc/clickhouse-server/users.d/
-
- # 将默认用户配置文件重命名
- mv default-password.xml default-pwd.xml
这时候不需要重启 clickhouse
就可以登录啦
- root@instance-0qymp8uo:/etc/clickhouse-server/users.d# clickhouse-client
- ClickHouse client version 22.8.4.7 (official build).
- Connecting to localhost:9000 as user default.
- Connected to ClickHouse server version 22.8.4 revision 54460.
-
- instance-0qymp8uo :)
clickhouse 密码设置
clickhouse
用户配置文件为 /etc/clickhouse-server/users.xml
。
clickhouse
密码有三种设置方式:明文、SHA256 和 SHA1 三种方式。
明文
明文密码则直接将要设置的密码放在标签:
<password></password>
当 password
标签为空时,代表免密码登录。
SHA256
通过下面命令生成密码,-c 表示要生成的长度;
PASSWORD=$(base64 < /dev/urandom | head -c14); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
生成的第一行为明文密码,用于自己使用;第二行为 sha256 加密字符串,需要配置到下面标签中:
<password_double_sha1_hex></password_double_sha1_hex>
double_shal
PASSWORD=$(base64 < /dev/urandom | head -c16); echo "$PASSWORD"; echo -n "$PASSWORD" | sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
生成的第一行为明文密码,用于自己使用;第二行为 double_shal 加密字符串,需要配置到下面标签中:
<password_double_sha1_hex></password_double_sha1_hex>
最后不需要重启 clickhouse
就可以登录啦
如果加载失败,可以尝试重启一下
sudo service clickhouse-server restart