Node.js: Configure SSH keys

This documentation is part of the Deploy with GitHub actions guide. View the full guide here: Learn how to deploy your Node.js code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero delivers a ready-to-use Node.js cloud environment designed to help you move faster:

  • Deploy to production in seconds with a simple git push. No extra tooling or manual setup is required.
  • Bring your own domain and benefit from automatic HTTPS certificates, keeping your application secure without extra configuration.
  • Automatic backups, one-click updates, and predictable pricing help you focus on shipping features, and Stackhero manages the infrastructure for you.
  • Built on private, dedicated infrastructure for consistent performance and strong security.

Save time and reduce operational overhead: you can have your application running on Stackhero's Node.js cloud hosting in just a few minutes.

SSH keys allow GitHub Actions to securely connect to your Node.js service when deploying your code. This is a crucial step for protecting your Stackhero services.

On your computer, you can generate new SSH keys using:

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

To view the public key you just created, run:

cat /tmp/ssh_key.pub

Next, in your Stackhero dashboard, select your production Node.js service and click the Configure button.

Get service settingsGet service settings

Continue with these steps:

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

Get service settingsGet service settings

Now, switch to GitHub and open your project repository. Click on Settings, then select Environments. Choose New environment.

Configuring GitHub environmentsConfiguring GitHub environments

Enter "production" for the Name and confirm.

Setting the environmentSetting the environment

Click the No restriction button, then choose Selected branches and tags.

Setting environment restrictionsSetting environment restrictions

Now 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 Environment secrets, click on Add secret.

Add secretAdd secret

To retrieve the private key you generated, run:

cat /tmp/ssh_key

In GitHub, use STACKHERO_SSH_PRIVATE_KEY as the Name and paste your private key into the Value field.

Setting the SSH private key secretSetting the SSH private key secret

Then, in Environment variables, click on Add variable.

Setting variablesSetting variables

Enter STACKHERO_ENDPOINT as the Name and paste your Node.js service endpoint into the Value field. You can find this endpoint in your Stackhero dashboard.

Setting the endpoint variableSetting the endpoint variable

If you have set a custom domain name for your service, use your custom domain instead of <XXXXXX>.stackhero-network.com.

For security, it is a good idea to remove the SSH keys from your computer after you have set them up on Stackhero and GitHub:

rm /tmp/ssh_key /tmp/ssh_key.pub