Files
Church-Music/legacy-site/documentation/md-files/SSH_QUICK_REFERENCE.md

4.7 KiB

Quick SSH Commands for Ubuntu Server Deployment

Connect to Server

ssh username@192.168.10.130

Replace username with your actual Ubuntu username.


Transfer Files to Server

# From Windows PowerShell
scp -r "E:\Documents\Website Projects\Church_SongLyric" username@192.168.10.130:/tmp/

Method 2: rsync (if available)

rsync -avz --progress "E:\Documents\Website Projects\Church_SongLyric/" username@192.168.10.130:/tmp/Church_SongLyric/

Method 3: WinSCP (GUI)

  1. Download WinSCP from https://winscp.net
  2. Connect to 192.168.10.130
  3. Drag and drop the Church_SongLyric folder

One-Line Deployment

After SSH'ing to the server:

sudo mv /tmp/Church_SongLyric /var/www/church-songlyric && cd /var/www/church-songlyric && chmod +x *.sh && ./ubuntu-setup-postgresql.sh

Troubleshooting SSH

Can't Connect

# Test if server is reachable
ping 192.168.10.130

# Test if SSH port is open
Test-NetConnection -ComputerName 192.168.10.130 -Port 22

Permission Denied

# On Ubuntu server, ensure SSH is running
sudo systemctl status ssh
sudo systemctl start ssh

SSH Keys (Optional Setup)

# Generate SSH key on Windows (if not exists)
ssh-keygen -t ed25519

# Copy key to server
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh username@192.168.10.130 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

# Now you can connect without password
ssh username@192.168.10.130

Quick Commands After Connection

# Check system info
uname -a
lsb_release -a

# Check disk space
df -h

# Check memory
free -h

# Check if PostgreSQL is installed
psql --version

# Check if Python3 is installed
python3 --version

# Check if Node.js is installed
node --version

Post-Deployment Verification

# Check service status
sudo systemctl status church-songlyric-backend

# View logs
sudo journalctl -u church-songlyric-backend -n 50

# Test API
curl http://192.168.10.130:5100/api/health

# Test via Nginx
curl http://192.168.10.130/api/health

# Check PostgreSQL
sudo -u postgres psql -c "\l" | grep church_songlyric

Common Management Tasks

Restart Services

sudo systemctl restart church-songlyric-backend
sudo systemctl restart nginx
sudo systemctl restart postgresql

View Live Logs

# Backend logs
sudo journalctl -u church-songlyric-backend -f

# Nginx access logs
sudo tail -f /var/log/nginx/access.log

# Nginx error logs
sudo tail -f /var/log/nginx/error.log

Database Access

# Connect to PostgreSQL
sudo -u postgres psql

# Or directly to your database
sudo -u postgres psql -d church_songlyric

# List all tables
\dt

# Exit
\q

Update Application

# After transferring new files to /tmp/
cd /var/www/church-songlyric
sudo rm -rf backend frontend  # Backup first!
sudo cp -r /tmp/Church_SongLyric/* .
sudo chown -R www-data:www-data .

# Rebuild
cd frontend
npm install
npm run build

cd ../backend
source venv/bin/activate
pip install -r requirements.txt

# Restart
sudo systemctl restart church-songlyric-backend

Emergency Commands

Stop Everything

sudo systemctl stop church-songlyric-backend
sudo systemctl stop nginx

Check Port Usage

# Check if port 5100 is in use
sudo netstat -tulpn | grep 5100

# Check who's using port 5100
sudo lsof -i :5100

Kill Process on Port

# Find process
sudo lsof -i :5100

# Kill it (replace PID with actual process ID)
sudo kill -9 PID

Database Backup

# Quick backup
pg_dump -h 192.168.10.130 -U songlyric_user -d church_songlyric > ~/backup_$(date +%Y%m%d_%H%M%S).sql

# Restore from backup
psql -h 192.168.10.130 -U songlyric_user -d church_songlyric < ~/backup_file.sql

Server Maintenance

Update System

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

Check Disk Space

df -h
du -sh /var/www/church-songlyric

Monitor Resources

# CPU and memory usage
htop

# Or simpler
top

# Disk I/O
iotop

Security

Firewall Status

sudo ufw status verbose

Add Firewall Rules

sudo ufw allow 5100/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Check Failed Login Attempts

sudo grep "Failed password" /var/log/auth.log | tail -20

Quick Reference Card - Print or save this for easy access!