📄 Linux Command Reference

Quick reference for managing the EC2 server — SSH access, VS Code, PM2, nginx, and common diagnostics.

Server: esqserver.com User: ec2-user Amazon Linux 2023
1

SSH from Terminal

Connect to the EC2 server from any Mac/Linux terminal or Windows PowerShell.

Basic Connection

Connect to EC2
ssh -i ~/.ssh/your-key.pem ec2-user@esqserver.com
Replace your-key.pem with your actual AWS key pair file name.
Fix key permissions (first time only)
chmod 400 ~/.ssh/your-key.pem
Required if SSH gives "WARNING: UNPROTECTED PRIVATE KEY FILE" error.

SSH Config Shortcut (Recommended)

Add this to ~/.ssh/config on your local machine so you can type ssh esquire instead of the full command:

~/.ssh/config entry
Host esquire HostName esqserver.com User ec2-user IdentityFile ~/.ssh/your-key.pem
After saving, connect with just: ssh esquire
ℹ️
On Windows, use PowerShell or Windows Terminal — SSH is built in. The key file goes in C:\Users\YourName\.ssh\ and permissions are set automatically.
2

VS Code + Claude Code

Use VS Code's Remote SSH extension to edit server files and run Claude Code directly on the EC2.

One-Time Setup

1
Open VS Code → Extensions (Ctrl+Shift+X) → search "Remote - SSH" → Install (by Microsoft)
2
Add the SSH config entry above to ~/.ssh/config on your local machine
3
Press F1 → type Remote-SSH: Connect to Host → select esquire
4
VS Code opens a new window connected to the EC2. You can now open folders, edit files, and use the integrated terminal as if you were on the server.
5
Open the integrated terminal (Ctrl+`) and run claude to start Claude Code on the server.

Reconnecting

Reconnect via Command Palette
F1 → Remote-SSH: Connect to Host → esquire
Or use the green >< button in the bottom-left corner of VS Code.

Running Claude Code on EC2

Start Claude Code
claude
Run in the VS Code integrated terminal while connected to the EC2. Claude Code opens in the current directory.
Start in a specific project folder
cd /home/ec2-user/project-folder && claude
⚠️
Keep the VS Code window open while Claude Code is running. Closing it or losing the SSH connection will interrupt Claude mid-task.
3

PM2 — Process Manager

PM2 keeps Node.js apps running in the background and restarts them automatically after a server reboot.

View Running Processes

List all processes
pm2 list
Shows all processes with their status, CPU, memory, and uptime. All should show online.
Current processes on this server
# ID Name Port Purpose 0 server 3000 Excel Upload (filemaker-node-uploader) 1 pdf-print 3001 PDF Print Server

Restart / Stop / Start

Restart a process
pm2 restart server pm2 restart pdf-print pm2 restart all # restart everything
Stop a process
pm2 stop server
Stops the process but keeps it in the list. Use pm2 start server to bring it back.
Start a new process
pm2 start app.js --name my-app
Remove a process from PM2
pm2 delete my-app

Logs

View live logs (all processes)
pm2 logs
Streams all output in real time. Press Ctrl+C to exit.
View logs for one process
pm2 logs server pm2 logs pdf-print
Show last 100 log lines
pm2 logs --lines 100

After Server Reboot

Save current process list (run once after adding new processes)
pm2 save
Saves the list so PM2 restores everything after a reboot. Already configured on this server.
4

Nginx — Web Server

Nginx acts as the front door — it handles HTTPS, routes /excel-upload/ to port 3000, /print/ to port 3001, and serves static files like the portal and spec docs.

Common Commands

Check config for errors (always run before reloading)
sudo nginx -t
Must show "syntax is ok" and "test is successful" before proceeding.
Reload nginx (apply config changes, no downtime)
sudo nginx -t && sudo systemctl reload nginx
The && means reload only runs if the test passes. Safe to use in production.
Restart nginx (full restart, brief interruption)
sudo systemctl restart nginx
Use reload instead unless nginx is unresponsive.
Check nginx status
sudo systemctl status nginx
Shows whether nginx is running, its PID, and recent log entries.

Config File Location

Edit the tools.esquireembroidery.com config
sudo nano /etc/nginx/conf.d/tools.esquireembroidery.com.conf
After editing, always run sudo nginx -t && sudo systemctl reload nginx.
Static files location
# Portal homepage and spec docs /var/www/portal/ index.html # → / spec/ index.html # → /spec/ filemaker_n8n_project_spec.html # → /spec/filemaker... excel_upload_spec.html # → /spec/excel... pdf_print_spec.html # → /spec/pdf... linux_commands.html # → /spec/linux...

View Nginx Logs

Live access log
sudo tail -f /var/log/nginx/access.log
Live error log
sudo tail -f /var/log/nginx/error.log
Check here first when a page returns 404, 502, or 500.
5

Server Health

Memory & CPU

RAM usage summary
free -h
Shows total, used, free, and available RAM. On t3.medium: ~4GB total.
Live CPU + memory by process
top
Press q to quit. Press M to sort by memory, P for CPU.
One-line snapshot (CPU, RAM, load)
echo "RAM:" && free -h | grep Mem && echo "Disk:" && df -h / | tail -1 && echo "Load:" && uptime

Disk

Disk usage
df -h /
Shows total, used, and available disk space on the main volume. Warning if above 80%.
Find what's using disk space
du -sh /home/ec2-user/* | sort -h
Shows size of each folder in the home directory, sorted smallest to largest.

Network & Ports

What ports are listening
ss -tlnp
Expected: 22 (SSH), 80 (HTTP), 443 (HTTPS), 3000 (server), 3001 (pdf-print), 5678 (n8n after install).
Check if a domain resolves correctly
curl -I https://tools.esquireembroidery.com/
Should return HTTP/2 200. Any other code indicates a problem.

Uptime & Reboots

How long the server has been running
uptime
Safe server reboot
sudo reboot
PM2 and nginx start automatically on reboot. Allow ~60 seconds before reconnecting.
6

Files & Logs

Navigation

List files in current directory
ls -la
Go to home directory
cd ~ # same as: cd /home/ec2-user
Show current directory path
pwd

Project Folders

Key directories on this server
# Node.js apps /home/ec2-user/filemaker-node-uploader/ # Excel Upload /home/ec2-user/pdf-print-server/ # PDF Print /home/ec2-user/portal/ # Portal source # Web files (served by nginx) /var/www/portal/ # Live portal + spec docs # Config /etc/nginx/conf.d/ # Nginx site configs

Viewing Files

View a file (scrollable)
less /path/to/file
Arrow keys to scroll, q to quit, / to search.
Follow a log file live
tail -f /path/to/logfile
Shows new lines as they're written. Ctrl+C to stop.
Search for text in a file
grep -r "search term" /home/ec2-user/
7

Git & GitHub

Version control commands for managing code changes and pushing to GitHub repositories.

One-Time Setup

Set your identity
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Required once per machine. Used in every commit you make.
Check current config
git config --list

Everyday Workflow

Check what has changed
git status
Shows modified, new, and deleted files. Run this before staging anything.
See the actual changes
git diff # unstaged changes git diff --staged # changes already staged
Stage files
git add filename # specific file git add . # everything in current folder
Commit staged changes
git commit -m "describe what changed and why"
Keep messages short and descriptive. Present tense works well: "Add nginx spec route".
Push to GitHub
git push
Sends your commits to the remote repository on GitHub.
Pull latest changes from GitHub
git pull
Fetches and merges the latest changes. Run before starting new work.

Branches

List all branches
git branch
The current branch is marked with *.
Create a new branch and switch to it
git checkout -b feature-name
Switch to an existing branch
git checkout main
Merge a branch into current branch
# Switch to main first, then merge git checkout main git merge feature-name

History

View compact commit history
git log --oneline -10
Shows the last 10 commits as one line each. Remove -10 for full history.
See what changed in a specific commit
git show abc1234
Replace abc1234 with the short commit hash from git log --oneline.

Undo Changes

Discard changes to a file (not yet staged)
git restore filename
Reverts the file to its last committed state. Cannot be undone.
Unstage a file (keep changes)
git restore --staged filename
Removes the file from the staging area but keeps your edits in the working directory.
Undo last commit (keep changes in working directory)
git reset --soft HEAD~1
Un-commits but keeps all your file changes so you can recommit differently.
Safely undo a commit that was already pushed
git revert HEAD
Creates a new commit that reverses the last one. Safe to use on shared branches.

Remote & Cloning

Clone a repository from GitHub
git clone https://github.com/org/repo.git
Check remote URL
git remote -v
Shows where git push and git pull point to.
Fetch without merging
git fetch
Downloads latest from GitHub but does not change your local files. Use git pull to also merge.
Push a new branch to GitHub for the first time
git push -u origin feature-name
The -u sets the upstream so future git push commands work without arguments.

GitHub Authentication on EC2

Check if GitHub CLI is installed
gh --version
Authenticate with GitHub (one-time)
gh auth login
Follow the prompts. Choose HTTPS and paste a Personal Access Token from github.com/settings/tokens.
Use SSH key instead of password (recommended)
# Generate a key (if you don't have one) ssh-keygen -t ed25519 -C "you@example.com" # Copy the public key cat ~/.ssh/id_ed25519.pub
Paste the output into GitHub → Settings → SSH Keys. Then use SSH clone URLs (git@github.com:…).
8

Directory Map

Where each URL, PM2 process, and project folder lives on this server.

tools.esquireembroidery.com — Served by nginx only (static files)

URLDirectory on server
tools.esquireembroidery.com//var/www/portal/index.html
tools.esquireembroidery.com/spec//var/www/portal/spec/

tools.esquireembroidery.com — nginx → PM2 (needs both)

URLPM2 processPortDirectory
/excel-upload/server3000/home/ec2-user/filemaker-node-uploader/
/print/pdf-print3001/home/ec2-user/pdf-print-server/
/fm-upload/fm-order-uploader3002/home/ec2-user/fm-order-uploader/
/n8n/n8n5678(n8n internal)

gemba-it.org — Separate domain

URLPM2 processPortDirectory
gemba-it.org/gemba-demos3003/home/ec2-user/gemba-demos/

GitHub Repos

Repo (Chibiroku/)Live directoryNotes
portal/home/ec2-user/portal/Source for /var/www/portal/
gemba-it-demos/home/ec2-user/gemba-it-demos/Mirror of gemba-demos (server/) + /var/www/gemba/ (public/)
fm-order-uploader/home/ec2-user/fm-order-uploader/
filemaker-node-uploader/home/ec2-user/filemaker-node-uploader/
pdf-print-server/home/ec2-user/pdf-print-server/
n8n-backups/home/ec2-user/n8n-backups/Auto-backed up daily at 7am via PM2
ℹ️
gemba-demos vs gemba-it-demos: PM2 runs the live server from gemba-demos/. The GitHub backup is gemba-it-demos/server/. When you update server code, keep both in sync.
9

Quick Reference

TaskCommand
Connect via SSHssh -i ~/.ssh/key.pem ec2-user@esqserver.com
Check all PM2 processespm2 list
Restart Excel Uploadpm2 restart server
Restart PDF Printpm2 restart pdf-print
View PM2 logs livepm2 logs
Test nginx configsudo nginx -t
Reload nginx (no downtime)sudo nginx -t && sudo systemctl reload nginx
Check RAMfree -h
Check diskdf -h /
Check open portsss -tlnp
Test site is upcurl -I https://tools.esquireembroidery.com/
View nginx errorssudo tail -f /var/log/nginx/error.log
Safe rebootsudo reboot
Git & GitHub
Check statusgit status
Stage all changesgit add .
Commitgit commit -m "message"
Push to GitHubgit push
Pull latestgit pull
View compact historygit log --oneline -10
Create & switch branchgit checkout -b feature-name
Discard file changesgit restore filename