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 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 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 ""
Set the public key
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 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 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