GitHub Actions SSH into AWS EC2

This tutorial shows ways to SSH into AWS EC2 without third-party actions.

Before you start, make sure you have the three things and make sure you can connect to EC2 with them:

  1. AWS EC2 remote hostname
  2. AWS EC2 username
  3. AWS EC2 SSH private key

Add Private Key to GitHub

GitHub allows you store sensitive information in "Secrets", click "New repository secret" to add your private key and save it.

If you want to add a new user for EC2 to separate users, you can check this tutorial.

Add Workflows

Under your repository's directory ".github", add directory "workflows". Then create a yml file to define GitHub actions, put the following content in the yml file, and replace all string starts with "!!" to your own value. Now you can trigger the GitHub Actions by pushing or pulling request to "main" branch.