← Back to list

Manually Trigger Git Action to deploy laravel project into EC2

Custome ssh port for security reasons

James Liang · 2025-03-10 10:10 · 2 claps · 1.5 min read
#github-actions #aws #ec2 #deployment
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud 🔓 · Open Source

Manually Trigger Git Action to deploy laravel project into EC2

Custome ssh port for security reasons

sudo vi /etc/ssh/sshd_config

Can set multiple Port. EX

Port 22
Port 1234

Restart SSH

sudo service ssh restart 

Add new port in ec2 scurity group inbound rules

Test connection

ss -tulpn | grep 1234

if restart ssh not wokring, restart ec2 instance.

Get an SSH Key

cd ~/.ssh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

You’ll also be asked to provide a passphrase. Leave this empty since we can’t enter

cat github-actions.pub >> ~/.ssh/authorized_keys

Set Github Actions secrets and variables

Set Github Action

name: Deploy

on:
  workflow_dispatch:

jobs:
  Deploy:
    name: Deploy to EC2
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4 
      - name: Build & Deploy
        env:
            PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
            HOSTNAME: ${{secrets.SSH_HOST}}
            PORT: ${{secrets.SSH_PORT}}
            USER_NAME: ${{secrets.SSH_USER_NAME}}

        run: |
          echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
          ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} -p ${PORT} '

              # Now we have got the access of EC2 and we will start the deploy .
              cd /var/www/releases &&
              '

Manually Trigger

Reference

https://www.taki.com.tw/blog/change-ssh-port/?srsltid=AfmBOopy-lDHMex1dBoPpyal4qqre_Eqt0XDGRAUbCj_oD84X0o39GAC

https://gist.github.com/raviagheda/c69ae5e884f4490b1af656dbd80c00dd

https://zellwk.com/blog/github-actions-deploy/


메타데이터
post_id
c8b9fc1909a8
slug
manually-trigger-script-in-ec2-from-git-action-c8b9fc1909a8
url
https://medium.com/@lalalili/manually-trigger-script-in-ec2-from-git-action-c8b9fc1909a8
canonical_url
https://medium.com/@lalalili/manually-trigger-script-in-ec2-from-git-action-c8b9fc1909a8
author_url
https://medium.com/@lalalili
status
ok
fetched_at
2026-07-20 17:28:32