When I completed the dbt Fundamentals course, I needed to connect dbt to a Snowflake account.
If you've connected the two platforms before, you may remember being able to authenticate using a username and password. However, this is no longer supported for connections to Snowflake. These now require one of the newer authentication methods, such as key-pair authentication.
What is key-pair authentication?
Instead of authenticating with a password, you create two cryptographic keys:
- A public key, which is stored in Snowflake.
- A private key, which remains securely stored on your computer or in dbt.
When dbt connects to Snowflake, it proves it owns the matching private key without ever sending that key to Snowflake. Although it sounds complicated, the setup only takes a few minutes.
Step 1: Install Git
The easiest way to generate the required keys on Windows is by installing Git for Windows, which you can get here. Once installed, launch Git Bash.
Step 2: Generate your key pair
First, create a folder to store your keys and move into it:
mkdir -p ~/.snowflake
cd ~/.snowflakeNow generate your private key:
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8You'll be asked to create a passphrase. Choose a strong password and make a note of it. You'll need it later when configuring dbt.
After entering your passphrase, Git Bash will create a private key as a file called rsa_key.p8 inside the .snowflake folder.
Next, generate the public key from your private key:
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pubYou'll be asked to enter the passphrase you just created. Nothing will appear on screen while you type your passphrase. This is normal. Type it as usual and press Enter. If successful, you should see:
writing RSA keyYou should now have two files:
rsa_key.p8- your private keyrsa_key.pub- your public key
You can check that both files are there by running:
lsIf you closed Git Bash at any point in this process the files won't disappear. You can simply open Git Bash again and return to the folder with:
cd ~/.snowflakeStep 3: Add the public key to Snowflake
To display your public key in Git Bash, run:
cat rsa_key.pubYou'll see something like:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...
-----END PUBLIC KEY-----Copy the key itself, then open Snowflake and run:
ALTER USER your_username
SET RSA_PUBLIC_KEY='paste_your_public_key_here';Only copy the key itself.
Do not include:
-----BEGIN PUBLIC KEY-----or:
-----END PUBLIC KEY-----Once you've run the command successfully, Snowflake is ready to accept connections using your private key.
Step 4: Configure dbt
First, return to Git Bash and display your private key:
cat rsa_key.p8This time, copy the entire output, including:
-----BEGIN ENCRYPTED PRIVATE KEY-----and:
-----END ENCRYPTED PRIVATE KEY-----Your private key should be kept secret. Don't share it with anyone or store it somewhere publicly accessible.
Create a new Snowflake connection (under 'connections' in dbt settings) and complete the usual connection details:
- Account
- Username
- Database
- Warehouse
For authentication:
- Select Key Pair Authentication
- Paste the entire contents of your
rsa_key.p8file into the private key field. - Include the
BEGIN ENCRYPTED PRIVATE KEYandEND ENCRYPTED PRIVATE KEYlines. - Enter the passphrase you chose when generating the key.
dbt will securely store your encrypted private key.
Step 5: Test the connection
Click Test Connection. Hopefully everything works first time. If it doesn't, check the format of your Snowflake account identifier. It should be in this format:
EXAMPLE01-ACCOUNT1In particular, if your Snowflake account identifier is displayed with a /, use a - instead when entering it in dbt.
For example:
EXAMPLE01/ACCOUNT1becomes:
EXAMPLE01-ACCOUNT1This can otherwise result in a fairly generic connection error from dbt. I learned this the hard way!
You're Done!
Hopefully you're now connected to Snowflake using key-pair authentication. I wanted to put together a quick, practical guide that walks through the process from start to finish, and I hope it saves you some time when setting up your own connection.

