Skip to content

SSH, Bare Repo, Git Push & Passwordless Login

Ringkasan

Video ini mencakup 3 topik deployment: (1) login ke server live via SSH dan menggunakan WP CLI, (2) membuat bare repository dengan post-receive hook untuk auto-deploy, dan (3) setup SSH keys agar tidak perlu ketik password setiap push.


BAGIAN 1: Login SSH ke Live Server

Aktifkan SSH di DreamHost Panel

  1. Buka DreamHost PanelManage Users
  2. Edit user yang digunakan untuk WordPress
  3. Ubah tipe dari SFTP menjadi SSH (Shell access)
  4. Set password baru (atau gunakan yang sama)

Login via SSH:

bash
ssh username@yourdomain.com
# Masukkan password saat diminta
  • Setelah login, Anda berada di home directory server (/home/username/)
  • Untuk keluar:
bash
exit

WP CLI (WordPress Command Line Interface)

DreamHost sudah menyediakan WP CLI di server. Navigasi ke folder WordPress:

bash
cd yourdomain.com

Contoh Perintah WP CLI:

bash
# Install dan aktifkan plugin
wp plugin install query-monitor --activate

# Deaktifasi plugin
wp plugin deactivate query-monitor

# Hapus plugin
wp plugin delete query-monitor

# List semua plugin
wp plugin list

Referensi lengkap: wp-cli.org → bisa manage themes, users, database, dll.


BAGIAN 2: Bare Repository & Post-Receive Hook

Konsep

Komputer Lokal          Server Live
┌──────────┐            ┌──────────────────┐
│  Git Repo │──push────→│  Bare Repo        │
│  (wp-content)         │  (our-repo/)      │
└──────────┘            │       │            │
                        │  post-receive hook │
                        │       │            │
                        │       ▼            │
                        │  wp-content/       │
                        │  (live files)      │
                        └──────────────────┘

Bare Repo = Git repo tanpa working directory (hanya terima push). Post-receive hook = Script yang berjalan otomatis setelah push berhasil → copy file ke folder live.

Step-by-Step di Server (via SSH):

1. Buat Bare Repository:

bash
cd ~
mkdir our-repo
cd our-repo
git init --bare

2. Buat Post-Receive Hook:

bash
cd hooks
touch post-receive
nano post-receive

3. Isi Script Post-Receive:

bash
#!/bin/bash
git --work-tree=/home/username/yourdomain.com/wp-content --git-dir=/home/username/our-repo checkout -f

Ganti username dan yourdomain.com sesuai setup Anda!

4. Buat File Executable:

bash
chmod +x post-receive

BAGIAN 3: Push dari Lokal ke Server

Kembali ke Komputer Lokal:

bash
exit
# (keluar dari SSH)

Tambah Remote Repository:

bash
git remote add live ssh://username@yourdomain.com/home/username/our-repo

Problem: Branch Name

DreamHost menggunakan master sebagai default, bukan main.

Jika branch lokal bernama main:

bash
git checkout -b master
# Buat branch baru 'master' dengan isi sama seperti 'main'

Push ke Server:

bash
git push live master
  • Pertama kali: ketik yes untuk fingerprint, lalu masukkan password
  • Post-receive hook otomatis copy file ke wp-content/ live

Fix Typo pada Remote URL:

bash
git remote set-url live ssh://username@yourdomain.com/home/username/our-repo

BAGIAN 4: Passwordless SSH (SSH Keys)

Mengapa?

Agar tidak perlu ketik password setiap kali git push.

Step 1: Cek SSH Key Lokal yang Sudah Ada

bash
ls ~/.ssh/
# Cari file id_ed25519 dan id_ed25519.pub

Step 2: Generate SSH Key (Jika Belum Ada)

bash
ssh-keygen -t ed25519 -C "email@anda.com"
  • Tekan Enter untuk default location
  • Tekan Enter untuk no passphrase (opsional)

Step 3: Lihat Public Key

bash
cat ~/.ssh/id_ed25519.pub
  • Copy seluruh output (mulai dari ssh-ed25519 sampai email)

Step 4: Pasang Public Key di Server

Login SSH ke server:

bash
ssh username@yourdomain.com
# (masukkan password terakhir kali!)

Buat folder .ssh dan file authorized_keys:

bash
cd ~
mkdir .ssh
cd .ssh
touch authorized_keys
nano authorized_keys

Paste public key, lalu save (Ctrl+O → Enter → Ctrl+X)

Set Permission yang Benar:

bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
PermissionArtinya
700Owner bisa read/write/execute, others: tidak ada akses
600Owner bisa read/write, others: tidak ada akses

Permission ini wajib! SSH menolak key jika permission terlalu longgar.

Step 5: Test Passwordless Login

bash
exit
# (keluar dari SSH)

ssh username@yourdomain.com
# Seharusnya langsung masuk TANPA password!

Step 6: Push Tanpa Password

bash
exit
# (keluar dari SSH)

git push live master
# Langsung push tanpa diminta password!

Workflow Deployment Lengkap

1. Edit file di komputer lokal (VS Code)
2. git add -A
3. git commit -m "deskripsi perubahan"
4. git push live master
   → SSH key otentikasi (tanpa password)
   → Bare repo menerima push
   → Post-receive hook berjalan
   → File ter-copy ke wp-content/ live
5. Refresh browser → perubahan sudah live!

Tips & Catatan Penting

  • Jangan edit file langsung di server — selalu edit di lokal, commit, push
  • uploads/ folder ada di .gitignore → gambar yang di-upload via WP Admin live TETAP aman
  • Plugin yang install via WP Admin live: tidak akan di-overwrite oleh push (kecuali plugin ada di commit)
  • Jika mau push theme baru (compile dulu): npm run build → add → commit → push