Python: Configure SSH keys

This documentation is part of the Deploy with GitHub Actions guide. View the full guide here: How to deploy your Python code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Python cloud solution designed to streamline your deployment process:

  • Deploy your application to production in seconds with a simple git push.
  • Use your own domain name, with automatic HTTPS certificate configuration for secure connections handled for you.
  • Rely on automatic backups, one-click updates, and predictable pricing, so you can focus on your code, not infrastructure management.
  • Benefit from strong performance and security on a private, dedicated infrastructure. Your environment is isolated and protected.

Save time and simplify your workflow: you can have your code running with Stackhero's Python cloud hosting in just 5 minutes.

SSH keys allow GitHub Actions to securely connect to your Python service for code deployment. This step is crucial for protecting your Stackhero services.

On your computer, you can generate new SSH keys by running:

ssh-keygen -C "" -f /tmp/ssh_key -N ""

First, display the public key you just generated:

cat /tmp/ssh_key.pub

Next, in your Stackhero dashboard, select your "production" Python service and click the "Configure" button.

Get service settingsGet service settings

Follow these steps:

  1. Under SSH public keys, click on Add a public key.
  2. For Description, enter GitHub Action.
  3. For Key, paste the public key you just copied.

Add public keyAdd public key

Go to your GitHub project page, click on Settings, then Environments. Choose New environment.

Configuring GitHub environmentsConfiguring GitHub environments

In the Name field, type "production" and confirm.

Setting the environmentSetting the environment

Click on the No restriction button and select Selected branches and tags.

Setting environment restrictionsSetting environment restrictions

Then, click on Add deployment branch or tag rule, enter "production" in the Name pattern field, and click Add rule.

Setting environment branchSetting environment branch Setting environment branchSetting environment branch

In the Environment secrets section, click Add secret.

Add secretAdd secret

Now, display the private key you generated earlier:

cat /tmp/ssh_key

In the secret setup, use STACKHERO_SSH_PRIVATE_KEY as the Name and paste the private key as the Value.

Setting the SSH private key secretSetting the SSH private key secret

Next, in the Environment variables section, click on Add variable.

Setting variablesSetting variables

Enter STACKHERO_ENDPOINT as the Name and paste your Python service endpoint as the Value. You will find this endpoint in your Stackhero dashboard.

Setting the endpoint variableSetting the endpoint variable

If you have customized your service's domain name, use the customized version instead of <XXXXXX>.stackhero-network.com.

For security, it is a good idea to remove the SSH keys from your computer now, since you will not need them anymore:

rm /tmp/ssh_key /tmp/ssh_key.pub