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 designed to help you move faster:
- Deploy to production in seconds with a simple
git push. No additional tools or manual configuration needed.- Use your own domain and take advantage of automatic HTTPS certificate setup, keeping your application secure with no extra steps.
- Enjoy automatic backups, one-click updates, and predictable, transparent pricing so you can focus on building features while Stackhero manages the infrastructure.
- Benefit from dedicated, private infrastructure for optimal performance and enhanced security.
Save time and simplify your operations: 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 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 ""
Set the public key
To display 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 settings
Continue with these steps:
- In SSH public keys, click on Add a public key.
- For Description, enter
GitHub Action. - For Key, paste the public key you copied earlier.
Get service settings
Set the private key
Now, switch to GitHub and open your project repository. Click on Settings, then select Environments. Choose New environment.
Configuring GitHub environments
Enter "production" for the Name and confirm.
Setting the environment
Click the No restriction button, then choose Selected branches and tags.
Setting environment restrictions
Now click on Add deployment branch or tag rule, enter "production" in the Name pattern field, and click Add rule.
Setting environment branch
Setting environment branch
In Environment secrets, click on Add secret.
Add 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 secret
Then, in Environment variables, click on Add variable.
Setting 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 variable
If you have set a custom domain name for your service, use your custom domain instead of <XXXXXX>.stackhero-network.com.
Delete the generated keys
For security, it is recommended to remove the SSH keys from your computer once they have been added to Stackhero and GitHub:
rm /tmp/ssh_key /tmp/ssh_key.pub