1. Pengenalan Linux Server
Linux adalah sistem operasi open-source yang mendominasi dunia server, cloud computing, dan infrastruktur IT global. Lebih dari 96% server cloud, 90% supercomputer, dan sebagian besar website di dunia berjalan di atas Linux. Memahami administrasi Linux server adalah skill fundamental yang wajib dikuasai oleh setiap profesional IT.
Linux server berbeda dari desktop — tidak ada GUI (Graphical User Interface) yang berjalan secara default. Semua konfigurasi dan operasi dilakukan melalui command line interface (CLI) menggunakan terminal. Ini membuatnya sangat efisien dalam penggunaan resource dan memungkinkan administrasi jarak jauh dengan mudah.
Distribusi Linux untuk Server
| Distribusi | Package Manager | Best For | LTS |
|---|---|---|---|
| Ubuntu Server | apt | Pemula, general purpose, cloud | 5 tahun |
| Debian | apt | Stabilitas, production server | 5 tahun |
| CentOS/Rocky Linux | dnf/yum | Enterprise, RHEL compatible | 10 tahun |
| Alpine Linux | apk | Container, minimal footprint | 2 tahun |
| Amazon Linux | dnf/yum | AWS EC2 instances | 3 tahun |
Struktur Direktori Linux
Beberapa perintah dasar yang wajib dikuasai sebelum mulai:
ls -la— Lihat semua file termasuk hiddencd /path— Pindah direktoricat file.txt— Baca isi filetail -f /var/log/syslog— Lihat log real-timeman command— Baca manual page perintahsudo— Jalankan perintah sebagai superuser
2. SSH: Akses Remote yang Aman
SSH (Secure Shell) adalah protokol kriptografis untuk mengakses server secara remote dengan aman. Semua data yang dikirim melalui SSH terenkripsi, sehingga aman untuk dikirimkan melalui jaringan publik. SSH menggantikan Telnet dan rlogin yang tidak aman.
Koneksi SSH Dasar
# Koneksi SSH dengan password
ssh user@192.168.1.100
# Koneksi SSH dengan port custom
ssh -p 2222 user@192.168.1.100
# Koneksi SSH dengan private key
ssh -i ~/.ssh/id_rsa user@192.168.1.100
# Copy file dari local ke server
scp file.txt user@server:/home/user/
# Copy file dari server ke local
scp user@server:/var/log/app.log ./
# Copy direktori secara rekursif
scp -r ./myapp user@server:/opt/
# SSH tunneling (port forwarding)
ssh -L 8080:localhost:80 user@server # Local port 8080 → server port 80
Konfigurasi SSH Key Authentication
SSH key authentication lebih aman daripada password karena menggunakan pasangan kunci kriptografis (public key dan private key).
# Langkah 1: Generate SSH key pair di mesin lokal
ssh-keygen -t ed25519 -C "admin@myserver.com"
# Tekan Enter untuk menyimpan di default (~/.ssh/id_ed25519)
# Masukkan passphrase (opsional tapi direkomendasikan)
# Output:
# Generating public/private ed25519 key pair.
# Your identification has been saved in /home/user/.ssh/id_ed25519
# Your public key has been saved in /home/user/.ssh/id_ed25519.pub
# Langkah 2: Copy public key ke server
ssh-copy-id user@192.168.1.100
# Atau secara manual:
cat ~/.ssh/id_ed25519.pub | ssh user@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
# Langkah 3: Coba login tanpa password
ssh user@192.168.1.100 # Harusnya tidak perlu password lagi
# Langkah 4 (Opsional): Disable password authentication
# Edit /etc/ssh/sshd_config di server:
# PasswordAuthentication no
# PermitRootLogin no
# ChallengeResponseAuthentication no
# Lalu restart sshd:
sudo systemctl restart sshd
Konfigurasi SSH Client yang Nyaman
# ~/.ssh/config di mesin lokal
# Server produksi
Host production
HostName 192.168.1.100
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
ServerAliveCountMax 3
# Server staging via bastion/jump host
Host staging
HostName 10.0.2.50
User admin
ProxyJump bastion
Host bastion
HostName 203.0.113.50
User jumpuser
Port 2222
# Sekarang cukup:
ssh production # = ssh -i ~/.ssh/id_ed25519 -p 22 deploy@192.168.1.100
ssh staging # = ssh melalui bastion → staging
- JANGAN pernah gunakan password sederhana untuk SSH
- SELALU gunakan SSH key authentication
- DISABLE root login langsung:
PermitRootLogin no - GANTI port default 22 ke port lain (misal 2222)
- GUNAKAN fail2ban untuk memblokir brute force attempts
3. User Management & Permissions
User Management adalah aspek kritis dalam server administration. Setiap user memiliki hak akses tertentu yang ditentukan oleh grup keanggotaan dan permission yang diberikan. Konsep ini merupakan fondasi keamanan Linux.
Mengelola User dan Grup
# Tambah user baru
sudo useradd -m -s /bin/bash -G sudo budi
# -m = buat home directory
# -s = set shell default
# -G = tambahkan ke grup
# Set password untuk user baru
sudo passwd budi
# Tambah user dengan spesifikasi lengkap
sudo useradd -m -d /home/sari -s /bin/bash -c "Web Developer" -G sudo,www-data sari
# Modifikasi user
sudo usermod -aG docker budi # Tambahkan user budi ke grup docker
sudo usermod -s /usr/sbin/nologin botuser # Disable interactive login
sudo usermod -L olduser # Lock/disable user account
# Hapus user
sudo userdel -r olduser # -r = hapus juga home directory
# Lihat informasi user
id budi # Lihat UID, GID, dan grup
whoami # User saat ini
who # Siapa yang sedang login
last -10 # 10 login terakhir
Linux File Permissions (chmod, chown)
Setiap file di Linux memiliki tiga jenis permission: read (r), write (w), dan execute (x) untuk tiga kategori: owner, group, dan others.
# Lihat permissions
ls -la /var/www/
# -rw-r--r-- 1 www-data www-data 4096 Jun 25 10:00 index.html
# ▲▲▲ ▲▲▲ ▲▲▲
# owner group others
# rwx rwx rwx
# Ubah permissions dengan chmod (numeric mode)
chmod 755 script.sh # rwxr-xr-x (owner=rwx, group=r-x, others=r-x)
chmod 644 index.html # rw-r--r-- (owner=rw, group=r, others=r)
chmod 600 id_rsa # rw------- (hanya owner, untuk private key SSH)
chmod 700 ~/.ssh # rwx------ (hanya owner untuk folder .ssh)
# Ubah permissions dengan chmod (symbolic mode)
chmod u+x script.sh # Tambah execute untuk owner
chmod g+w file.txt # Tambah write untuk group
chmod o-rwx secret.txt # Hapus semua permission untuk others
chmod a+r readme.txt # Tambah read untuk semua (all)
# Ubah owner dan group
sudo chown budi:www-data /var/www/html
sudo chown -R www-data:www-data /var/www/html # Rekursif
# Setgid: file baru otomatis punya group parent directory
chmod g+s /var/www/shared/
# Setgid: sticky bit untuk folder shared
chmod +t /tmp # Hanya owner file yang bisa hapus file di /tmp
# Angka dalam chmod:
# r=4, w=2, x=1
# 7=4+2+1 (rwx), 6=4+2 (rw-), 5=4+1 (r-x), 4=r-- (read only)
Angka Owner Group Others
← Berbahaya!
← Untuk script/eksekusi
← Untuk file biasa
← Private key
← Read-only owner
← Private folder
r = 4 (read)
w = 2 (write)
x = 1 (execute)
Contoh: 755 = 7(owner) + 5(group) + 5(others)
= rwx + r-x + r-x
sudo: Hak Akses Root Sementara
# Jalankan perintah sebagai root
sudo apt update
# Edit file sebagai root
sudo nano /etc/nginx/nginx.conf
# Switch ke root shell (gunakan dengan hati-hati)
sudo -i
# Jalankan perintah sebagai user lain
sudo -u www-data cat /var/www/secret.txt
# Edit sudoers file dengan aman (JANGAN langsung edit /etc/sudoers)
sudo visudo
# Tambahkan user ke grup sudo
sudo usermod -aG sudo budi
# Contoh /etc/sudoers.d/custom:
# budi ALL=(ALL) ALL # Full access dengan password
# deploy ALL=(ALL) NOPASSWD: ALL # Full access tanpa password
# www-data ALL=(ALL) NOPASSWD: /usr/sbin/nginx # Hanya nginx command
4. systemd: Service Manager Modern
systemd adalah sistem init dan service manager yang digunakan oleh sebagian besar distribusi Linux modern (Ubuntu, Debian, CentOS, dll). systemd mengelola semua service yang berjalan di sistem, mulai dari web server hingga database.
Perintah systemctl yang Sering Digunakan
# Start/stop/restart service
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # Reload config tanpa restart
# Enable/disable service (auto-start saat boot)
sudo systemctl enable nginx
sudo systemctl disable nginx
# Lihat status service
sudo systemctl status nginx
# Output: active (running) sejak Mon 2026-06-25
# Lihat semua service yang aktif
systemctl list-units --type=service --state=running
# Lihat semua service yang failed
systemctl --failed
# Lihat log service tertentu
journalctl -u nginx -f # Follow real-time
journalctl -u nginx --since today # Log hari ini saja
journalctl -u nginx --since "2026-06-25 10:00" --until "2026-06-25 12:00"
journalctl -u nginx -n 100 # 100 baris log terakhir
journalctl -p err -u nginx # Hanya log level error
# Enable dan start sekaligus
sudo systemctl enable --now nginx
Membuat Custom Service Unit
Anda bisa membuat service systemd untuk aplikasi custom (Node.js, Python, Go, dll).
[Unit]
Description=My Node.js Application
Documentation=https://docs.myapp.com
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
User=deploy
Group=deploy
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=10
Environment=NODE_ENV=production
Environment=PORT=3000
EnvironmentFile=/opt/myapp/.env
# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/opt/myapp/logs /opt/myapp/uploads
PrivateTmp=true
# Resource limits
LimitNOFILE=65535
LimitNPROC=4096
# Logging
StandardOutput=journal
StandardError=journal
SyslogIdentifier=myapp
[Install]
WantedBy=multi-user.target
# Reload systemd untuk membaca unit file baru
sudo systemctl daemon-reload
# Enable dan start service
sudo systemctl enable --now myapp
# Cek status
sudo systemctl status myapp
# Lihat log aplikasi
journalctl -u myapp -f
# Edit unit file (buka editor)
sudo systemctl edit myapp # Untuk override/drop-in
Dibanding init.d/supervisor lama, systemd menawarkan:
- Dependency management: Service mulai sesuai urutan yang tepat
- Auto restart: Restart otomatis jika service crash
- Resource control: Limit CPU, memory, I/O per service
- Unified logging: Semua log di journalctl
- Socket activation: Service mulai saat ada request
5. Cron: Penjadwalan Tugas Otomatis
Cron adalah sistem penjadwalan tugas yang berjalan di background (cron daemon) untuk menjalankan perintah atau script secara otomatis sesuai jadwal yang ditentukan. Cron sangat berguna untuk backup otomatis, rotasi log, cleanup, monitoring, dan tugas periodik lainnya.
Sintaks Crontab
menit (0-59)
jam (0-23)
hari dalam bulan (1-31)
bulan (1-12)
hari dalam minggu (0-7, 0&7=Minggu)
* * * * * /path/to/command arg1 arg2
Contoh:
*/5 * * * * = Setiap 5 menit
0 */2 * * * = Setiap 2 jam (pada menit 0)
0 2 * * * = Setiap hari jam 2 pagi
0 0 * * 0 = Setiap Minggu jam 00:00
0 9 * * 1-5 = Setiap hari kerja jam 9 pagi
30 1 1,15 * * = Tanggal 1 dan 15 setiap bulan jam 01:30
# Edit crontab untuk user saat ini
crontab -e
# Lihat crontab saat ini
crontab -l
# Edit crontab untuk user lain (root only)
sudo crontab -u deploy -e
# Contoh crontab entries:
# Backup database setiap jam 2 pagi
#
0 2 * * * /opt/scripts/backup_db.sh >> /var/log/backup.log 2>&1
# Membersihkan file temporary setiap hari jam 3 pagi
0 3 * * * find /tmp -type f -mtime +7 -delete
# Restart web server setiap Minggu jam 4 pagi
0 4 * * 0 systemctl restart nginx
# Cek disk usage setiap 6 jam
0 */6 * * * /opt/scripts/check_disk.sh
# Deploy otomatis setiap push ke main (via webhook, bukan cron)
# Tapi cron bisa pull repo setiap 5 menit:
*/5 * * * * cd /opt/myapp && git pull origin main 2>&1 | logger -t autodeploy
# Kirim laporan harian jam 8 pagi
0 8 * * * /opt/scripts/daily_report.sh | mail -s "Daily Report" admin@company.com
# Cron dengan timezone (systemd)
# Tambahkan CRON_TZ=Asia/Jakarta di awal crontab
CRON_TZ=Asia/Jakarta
0 7 * * * /opt/scripts/morning_task.sh
Alternatif Cron: systemd Timer
# /etc/systemd/system/backup.timer
[Unit]
Description=Backup database harian
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target
# /etc/systemd/system/backup.service
[Unit]
Description=Run database backup
[Service]
Type=oneshot
ExecStart=/opt/scripts/backup_db.sh
User=deploy
# Aktifkan timer
sudo systemctl enable --now backup.timer
# Lihat semua timer aktif
systemctl list-timers --all
6. Disk & Storage Management
Disk management mencakup pemantauan penggunaan disk, partisi, format, mounting, dan manajemen storage. Memahami disk management sangat penting untuk menjaga server tetap berjalan optimal dan mencegah masalah kehabisan ruang disk.
Memantau Penggunaan Disk
# Lihat penggunaan disk (human-readable)
df -h
# Filesystem Size Used Avail Use% Mounted on
# /dev/sda1 50G 32G 16G 67% /
# /dev/sdb1 200G 45G 145G 24% /data
# Lihat penggunaan per direktori
du -sh /var/log # Total ukuran /var/log
du -sh /home/* # Ukuran setiap home directory
du -sh /* 2>/dev/null # Ukuran setiap direktori root
# Top 10 direktori terbesar
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -10
# Lihat info block device
lsblk
# NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
# sda 8:0 0 50G 0 disk
# ├─sda1 8:1 0 50G 0 part /
# sdb 8:16 0 200G 0 disk
# └─sdb1 8:17 0 200G 0 part /data
# Lihat info filesystem
sudo blkid # UUID dan tipe filesystem
sudo fdisk -l # Tabel partisi lengkap
Partisi dan Format Disk Baru
# Langkah 1: Buat partisi baru pada /dev/sdb
sudo fdisk /dev/sdb
# Commands: n (new), p (primary), 1 (number), w (write)
# Langkah 2: Format partisi dengan ext4
sudo mkfs.ext4 /dev/sdb1
# Langkah 3: Buat mount point
sudo mkdir -p /data
# Langkah 4: Mount partisi
sudo mount /dev/sdb1 /data
# Langkah 5: Tambahkan ke /etc/fstab untuk auto-mount saat boot
echo 'UUID=xxxx-xxxx /data ext4 defaults,noatime 0 2' | sudo tee -a /etc/fstab
# Cek fstab sebelum reboot (penting!)
sudo mount -a
# Resize partisi ext4 (jika disk di-expand di cloud)
sudo resize2fs /dev/sdb1
# Lihat disk I/O
iostat -xz 1 5 # Monitor I/O setiap 1 detik, 5 kali
iotop # Top untuk disk I/O (seperti top)
Swap Space Management
# Cek swap saat ini
sudo swapon --show
free -h
# Buat swap file 2GB
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Tambahkan ke fstab agar persisten
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Tuning swappiness (10 = gunakan swap hanya saat benar-benar perlu)
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
7. Networking & Firewall
Networking adalah skill penting untuk mengelola server. Anda perlu memahami cara mengkonfigurasi jaringan, memantau koneksi, dan mengamankan server dengan firewall.
Perintah Networking Penting
# Lihat konfigurasi IP
ip addr show # Atau: ip a
ip route show # Tabel routing
# Cek konektivitas
ping -c 4 google.com
traceroute google.com
# Cek port yang sedang terbuka (listening)
ss -tlnp # TCP listening ports
ss -ulnp # UDP listening ports
ss -tp # Semua koneksi TCP aktif
# Alternatif lama (masih banyak digunakan)
netstat -tlnp # TCP listening
netstat -anp | grep :80 # Cek koneksi ke port 80
# DNS lookup
dig beebanelabs.pages.dev
nslookup beebanelabs.pages.dev
host beebanelabs.pages.dev
# Test koneksi ke port tertentu
nc -zv 192.168.1.100 22 # Test SSH
telnet 192.168.1.100 80 # Test HTTP
# Download file
wget https://example.com/file.tar.gz
curl -O https://example.com/file.tar.gz
curl -I https://example.com # Hanya headers
# Lihat hostname dan IP
hostname
hostname -I
UFW: Uncomplicated Firewall
UFW adalah front-end yang memudahkan konfigurasi iptables untuk Ubuntu/Debian. Ini adalah firewall yang direkomendasikan untuk pemula.
# Aktifkan UFW
sudo ufw enable
# Set default policy
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Izinkan port spesifik
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
sudo ufw allow 8080/tcp # Custom app
# Izinkan dari IP tertentu
sudo ufw allow from 192.168.1.0/24 to any port 22 # SSH dari LAN saja
sudo ufw allow from 10.0.0.0/8 to any port 3306 # MySQL dari internal
# Izinkan dengan deskripsi
sudo ufw allow 8443/tcp comment 'Grafana HTTPS'
# Hapus rule
sudo ufw delete allow 8080/tcp
sudo ufw delete 3 # Hapus rule nomor 3
# Lihat status dan rules
sudo ufw status verbose
sudo ufw status numbered
# Disable firewall (untuk debugging)
sudo ufw disable
Netplan: Konfigurasi Jaringan Modern
# Konfigurasi static IP (Ubuntu 20.04+)
network:
version: 2
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
- 1.1.1.1
# Terapkan konfigurasi
sudo netplan apply
# Cek hasil
sudo netplan try # Coba dulu, auto-rollback jika gagal
8. Security Hardening
Security hardening adalah proses mengamankan server Linux dari berbagai ancaman keamanan. Ini mencakup konfigurasi SSH yang aman, firewall, automatic updates, intrusion detection, dan best practices keamanan lainnya.
Checklist Security Hardening
| No. | Langkah | Prioritas |
|---|---|---|
| 1 | Disable root login SSH | 🔴 Kritis |
| 2 | Gunakan SSH key authentication | 🔴 Kritis |
| 3 | Aktifkan firewall (UFW/iptables) | 🔴 Kritis |
| 4 | Update sistem secara berkala | 🔴 Kritis |
| 5 | Install & konfigurasi fail2ban | 🟡 Penting |
| 6 | Nonaktifkan service yang tidak diperlukan | 🟡 Penting |
| 7 | Set password policy yang ketat | 🟡 Penting |
| 8 | Audit log secara berkala | 🟡 Penting |
| 9 | Install intrusion detection (AIDE/rkhunter) | 🟢 Direkomendasikan |
| 10 | Enkripsi data at rest & in transit | 🟢 Direkomendasikan |
Implementasi Security Hardening
# 1. Update sistem
sudo apt update && sudo apt upgrade -y
sudo apt autoremove -y
# 2. Install unattended-upgrades untuk auto security patches
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# 3. Install & konfigurasi fail2ban
sudo apt install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# Edit /etc/fail2ban/jail.local:
cat > /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
banaction = ufw
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 86400
EOF
sudo systemctl enable --now fail2ban
# 4. Harden SSH config (/etc/ssh/sshd_config)
sudo sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/#MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config
sudo sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 300/' /etc/ssh/sshd_config
sudo sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 2/' /etc/ssh/sshd_config
echo "AllowUsers deploy admin" | sudo tee -a /etc/ssh/sshd_config
sudo systemctl restart sshd
# 5. Kernel hardening (/etc/sysctl.conf)
cat > /etc/sysctl.d/99-security.conf << 'EOF'
# Disable IP forwarding (jika bukan router)
net.ipv4.ip_forward = 0
# Disable ICMP redirect
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
# Enable SYN cookie (anti SYN flood)
net.ipv4.tcp_syncookies = 1
# Log Martian packets
net.ipv4.conf.all.log_martians = 1
# Disable IPv6 jika tidak diperlukan
net.ipv6.conf.all.disable_ipv6 = 1
EOF
sudo sysctl --system
# 6. Scan untuk malware
sudo apt install rkhunter
sudo rkhunter --check --skip-keypress
- SELALU buat backup sebelum mengubah konfigurasi keamanan
- TEST SSH connection di terminal baru sebelum menutup sesi yang ada
- PANTAU log keamanan secara berkala:
sudo tail -f /var/log/auth.log - PRINCIPLE OF LEAST PRIVILEGE: Berikan hak akses seminimal mungkin yang diperlukan
- DOKUMENTASIKAN setiap perubahan konfigurasi keamanan
9. Quiz: Uji Pemahamanmu!
Setelah membaca tutorial di atas, jawablah 5 pertanyaan berikut untuk menguji pemahamanmu tentang Linux Server Administration: