Skip to content

godwill1224/ssh-cicd-deploy-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

📦 CI/CD Deployment with GitHub Actions + SSH

This project uses GitHub Actions to automatically deploy your app to a remote server whenever:

  • code is pushed to main
  • or the nightly schedule runs

Deployment happens through SSH, so GitHub securely connects to your server and runs commands like:

git pull origin main
docker compose up -d --build

🚀 How It Works

Flow

Push to main
     ↓
GitHub Actions runs
     ↓
SSH into server
     ↓
Pull latest code
     ↓
Restart app

🧩 Requirements

Before starting, you need:

  • Ubuntu/Linux server (VPS or VM)
  • Git installed
  • Your project already cloned on server
  • Docker / Node / Python (depending on your stack)
  • GitHub repo

🔐 Step 1 — Generate SSH Key (for deployment)

You need a dedicated SSH key for GitHub Actions (NOT your personal one).

On your local machine run:

ssh-keygen -t ed25519 -C "github-deploy" -f github-deploy-key

Press Enter for no password.

This creates:

github-deploy-key        ← private key (SECRET)
github-deploy-key.pub    ← public key (SAFE)

🔑 Step 2 — Add Public Key to Your Server

Copy the public key:

cat github-deploy-key.pub

On your server:

mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys

Paste the public key.

Then fix permissions:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

🌍 Step 3 — Add GitHub Secrets

Go to your repository:

Open:

Settings → Secrets and variables → Actions → New repository secret


Add these secrets

1️⃣ SERVER_IP

Your server IP

123.45.67.89

2️⃣ DEPLOYER_USER

Your SSH user

ubuntu

or

root

3️⃣ DEPLOYER_SSH

Paste PRIVATE key content

cat github-deploy-key

Copy EVERYTHING including:

-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

⚠️ Never share this key publicly.


4️⃣ FOLDER_PATH

Path to project on server

Example:

/var/www/myapp

📁 Step 4 — Place Workflow File

Create:

.github/workflows/deploy.yml

Paste your workflow file there.

Folder structure:

project/
 ├─ .github/
 │   └─ workflows/
 │       └─ deploy.yml
 ├─ src/
 ├─ docker-compose.yml
 └─ README.md

🧪 Step 5 — Test Deployment

Push to main:

git add .
git commit -m "test deploy"
git push origin main

Then:

GitHub → Actions tab

You should see:

✓ Deploy to Server
✓ Deployment finished successfully

⚙️ Example Server Deploy Commands

Inside workflow SSH script you can run:

Docker

docker compose down
docker compose up -d --build

Node

npm install
npm run build
pm2 restart all

Python

pip install -r requirements.txt
sudo systemctl restart app

🛠 Troubleshooting

Permission denied (publickey)

Fix:

chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

Host key verification failed

Add:

ssh youruser@server-ip

Accept fingerprint once.


Secrets not working

Check:

  • No spaces
  • Private key includes BEGIN/END lines
  • Secret names match exactly

🔒 Security Tips

✔ Use separate deploy key ✔ Do NOT reuse personal SSH key ✔ Do NOT commit private key ✔ Limit server user permissions ✔ Prefer non-root user


✅ Done!

Now every push to main automatically deploys 🚀


About

Production-ready CI/CD pipeline using GitHub Actions and SSH for automated server deployments with zero manual steps.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors