Ruby: Configure SSH keys

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

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby 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 Ruby cloud hosting solution!

To allow GitHub Actions to deploy your code, you will need to set up SSH keys. This ensures only authorized actions can connect to your Stackhero services, keeping your deployments secure.

You can generate a new set of SSH keys on your computer using:

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

Next, retrieve the public key you just created:

cat /tmp/ssh_key.pub

In the Stackhero dashboard, select your "production" Ruby service and click the "Configure" button. Get service settingsGet service settings

Then:

  1. Under SSH public keys, click Add a public key.
  2. For Description, enter GitHub Action.
  3. For Key, paste in the public key content from your computer.

Get service settingsGet service settings

Now, head to the GitHub website and open your project.

Go to Settings > Environments, then click New environment. Configuring GitHub environmentsConfiguring GitHub environments

Name your environment "production" and save it. Setting the environmentSetting the environment

Click the No restriction button and choose Selected branches and tags. Setting environment restrictionsSetting environment restrictions

Click Add deployment branch or tag rule, enter "production" as the pattern, and add the rule. Setting environment branchSetting environment branch Setting environment branchSetting environment branch

To store your SSH private key securely, go to Environment secrets and click Add secret. Add secretAdd secret

Retrieve your private key from your computer:

cat /tmp/ssh_key

For Name, enter STACKHERO_SSH_PRIVATE_KEY. For Value, paste your private key content. Setting the SSH private key secretSetting the SSH private key secret

Next, add your Ruby service's endpoint as an environment variable. Click on Add variable in Environment variables. Setting variablesSetting variables

For Name, enter STACKHERO_ENDPOINT. For Value, paste the endpoint for your Ruby service, which you can find in your Stackhero dashboard. Setting the endpoint variableSetting the endpoint variable

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

Once your keys are set up in Stackhero and GitHub, you can delete them from your computer for security.

rm /tmp/ssh_key /tmp/ssh_key.pub