- Published on
How to create a Key-pair authentication connection in Snowflake
- Authors
- Name
- Gene Zhang
Prerequisites
- Login with a user with the
ACCOUNTADMIN
role withsnowsql
.
% snowsql -a <account> -u user_name;
- Create database and load data:
https://docs.snowflake.com/en/user-guide/tutorials/snowflake-in-20minutes
Create a key pair connection
Create a key pair following: https://docs.snowflake.com/en/user-guide/key-pair-auth
Create a user and assign the public key:
CREATE USER rsa_user PASSWORD='Snow@123' DEFAULT_ROLE = public;
ALTER USER RSA_USER SET RSA_PUBLIC_KEY='MII...';
- Grant permissions:
GRANT USAGE on WAREHOUSE COMPUTE_WH to role PUBLIC;
GRANT USAGE on DATABASE SF_TUTS to role PUBLIC;
GRANT USAGE on SCHEMA PUBLIC to role PUBLIC;
GRANT ALL on TABLE EMP_BASIC to role PUBLIC;
- Optional: set default warehouse:
ALTER USER RSA_USER SET DEFAULT_WAREHOUSE = COMPUTE_WH;
Test connection
% snowsql -a bawupxs-dcb65020 -u rsa_user --private-key-path ~/.rsa_key.p8
use warehouse COMPUTE_WH;
use database SF_TUTS;
use schema PUBLIC;
select * from EMP_BASIC limit 3;
insert into EMP_BASIC (FIRST_NAME,LAST_NAME) values
('jane1', 'doe1'),
('jane2', 'doe2');
delete from EMP_BASIC where FIRST_NAME in ('jane1', 'jane2');