Node.js: Configure SSH keys

This documentation is part of the Deploy with GitHub Actions guide. You can view the complete guide here: Learn how to deploy your Node.js code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Node.js cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Node.js cloud hosting solution!

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

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

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

To display the public key you have 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 will 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 recommended to delete the SSH keys from your computer once you have added them to Stackhero and GitHub:

rm /tmp/ssh_key /tmp/ssh_key.pub