Python Connector for Snowflake

Obtaining credentials for key pair authentication - Python Connector for Snowflake

Obtaining credentials for key pair authentication

To use key pair authentication to connect to Snowflake, generate an RSA key pair using OpenSSL and assign the public key to your Snowflake user.

  1. Open a terminal.
  2. Generate a private key. Replace <your_private_key> with a file name for the private key.
    • For an unencrypted private key:
    • openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out <your_private_key> -nocrypt
      
    • For an encrypted private key:
    • openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out <your_private_key>
      

      When prompted, enter an encryption password.

  3. Generate the public key from the private key. Replace <your_private_key> with your private key file name and <your_public_key> with a file name for the public key.
    openssl rsa -in <your_private_key> -pubout -out <your_public_key>
    

    If the private key is encrypted, enter the encryption password you used to encrypt it when prompted.

  4. Open the public key file and copy the key value. Exclude the -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- lines and remove all line breaks.
  5. In Snowflake, open a worksheet.
  6. Run the following command to assign the public key to your Snowflake user. Replace <your_snowflake_user> with the name of your Snowflake user and <your_public_key_value> with the public key value you copied in the previous step.
    ALTER USER <your_snowflake_user> SET RSA_PUBLIC_KEY='<your_public_key_value>';
    
  7. Use the private key file (and its passphrase, if encrypted) in the PrivateKey and Passphrase arguments when connecting. For more information, see Connecting to Snowflake.
© 2022-2026 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback