Question
How can I connect to ClickHouse using SSH Key Authentication?
Answer
- Use ssh-keygen to create the keypair. Example:
➜ new ssh-keygen \
-t ed25519 \
> -f /Users/testuser/.ssh/ch_key
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/testuser/.ssh/ch_key
Your public key has been saved in /Users/testuser/.ssh/ch_key.pub
.....- Use the public key (ch_key.pub in above example) to create the USER.
clickhouse-cloud :) CREATE USER abcuser IDENTIFIED WITH ssh_key BY KEY 'AAAABBBcdE1lZDI1NTE5AAAAIISdl4CrGM8mckXBUXLjL3ef9XwnycDWEvBPu3toB40m' TYPE 'ssh-ed25519';
CREATE USER abcuser IDENTIFIED WITH ssh_key BY KEY AAAABBBcdE1lZDI1NTE5AAAAIISdl4CrGM8mckXBUXLjL3ef9XwnycDWEvBPu3toB40m TYPE `ssh-ed25519`
Query id: 34c6aad6-5f88-4c80-af7a-7d37c91ba7d5
Ok.-
Run
SHOW usersto confirm the user creation. -
Grant default_role to the user (optional).
clickhouse-cloud :) grant default_role to abcuser;
GRANT default_role TO abcuser
Query id: 4a054003-220a-4dea-8e8d-eb1f08ee7b10
Ok.
0 rows in set. Elapsed: 0.137 sec.- Use the private key now to authenticate against the service.
➜