# Managing VPS Instances

Complete guide to managing, monitoring, and maintaining your VPS instances.

## Overview

Once your VPS is created, you can manage it through the dashboard or SSH. This guide covers all management operations.

## Instance Dashboard

Access your VPS dashboard:

1. Go to **Pods** in the main menu
2. Click on your instance name
3. View the instance dashboard

### Dashboard Sections

**Overview Tab**:
- Instance status
- Resource usage charts
- Connection information
- Quick actions (Start, Stop, Reboot)

**Metrics Tab**:
- Real-time performance graphs
- CPU usage
- Memory utilization
- Disk I/O
- Network traffic

**Snapshots Tab**:
- Create and manage snapshots
- Restore from snapshots
- Delete old snapshots

**Console Tab**:
- Full **graphical VNC console** in the browser — no SSH required
- Emergency access when SSH is unavailable (boot issues, firewall lockout, etc.)

## Instance Operations

### Start Instance

Start a stopped instance:

1. Go to your instance dashboard
2. Click **Start** button
3. Instance boots in 30-60 seconds

**Cost Note**: Instances are billed whether running or stopped. Starting simply resumes compute activity.

### Stop Instance

Shut down your instance:

1. Go to your instance dashboard
2. Click **Stop** button
3. Confirm the action
4. Instance shuts down in 30-60 seconds

**Important**:
- All data is preserved
- Still billed at the full rate (delete to stop billing)
- Can start anytime
- Network connections are lost

**Graceful Shutdown**:
```bash
# Prefer SSH shutdown for clean stop
ssh root@your-ip
sudo shutdown -h now
```

### Force Stop (Stuck Instances)

If an instance gets stuck in a transitional state (starting, stopping, rebooting), use **Force Stop** to force-kill it and return it to a stopped state.

1. Open the actions menu on the instance
2. Click **Force stop**
3. Confirm in the dialog

Force Stop is only offered when the platform detects that an instance is stuck.

### Reboot Instance

Restart your instance:

1. Go to your instance dashboard
2. Click **Reboot** button
3. Confirm the action
4. Instance reboots in 1-2 minutes

**Use Cases**:
- After kernel updates
- To apply system changes
- Troubleshooting issues
- After configuration changes

**SSH Reboot**:
```bash
sudo reboot
```

### Reinstall OS

Reinstall the operating system on the **same** instance — handy for starting fresh without changing the IP address.

1. Open the actions menu and choose **Reinstall OS**
2. Pick the OS image and confirm
3. Your custom cloud-init script (if any) runs again on first boot

**Warning**: Reinstalling **erases all data on the disk**. Take a snapshot first if you need to keep anything.

### Redeploy

If an instance is stuck in an **error** or **pending** state, **Redeploy** re-runs its deployment (with detailed logs) — often the quickest way to recover without recreating the instance.

### Delete Instance

**Warning**: This permanently deletes your instance and all data!

**Before Deleting**:
1. ✅ Backup important data
2. ✅ Create snapshot if needed
3. ✅ Update DNS records
4. ✅ Notify team members
5. ✅ Document configuration

**Delete Steps**:
1. Go to your instance dashboard
2. Click **Delete** button
3. Type instance name to confirm
4. Click **Confirm Delete**
5. Instance deleted in 1-2 minutes

**Cannot be undone!**

## Editing Instance Configuration

### Change Instance Name

1. Go to instance dashboard
2. Click **Edit** button
3. Update name
4. Click **Save**

### Resize (Profile, CPU, RAM, Disk)

From the instance **Edit** page you can move to a different resource profile, or fine-tune CPU, memory, and disk directly. A live price estimate updates as you change values.

- **Disk can be grown but not shrunk** — profiles whose maximum disk is smaller than your current disk are disabled
- Resizing briefly powers the instance off while resources are applied, then powers it back on
- Billing adjusts from the hour the resize takes effect

See [Resource Profiles → Resizing](https://docs.danubedata.ro/vps-profiles#resizing).

### Attach/Detach Firewalls

**Attach Firewall**:
1. Go to instance dashboard
2. Click **Edit** button
3. Select firewall from dropdown
4. Click **Save**
5. Rules apply immediately

**Detach Firewall**:
1. Click **Edit** button
2. Remove firewall selection
3. Click **Save**
4. All traffic allowed (not recommended!)

### Add/Remove SSH Keys

**Add Key**:
1. Go to instance dashboard
2. Click **SSH Keys** section
3. Click **Add Key**
4. Select existing key or add new
5. Key added to `~/.ssh/authorized_keys`

**Remove Key**:
1. Go to **SSH Keys** section
2. Click **Remove** next to key
3. Key removed from server

## Resource Monitoring

Every instance keeps **7 days of historical metrics**. You can set [metric alerts](https://docs.danubedata.ro/monitoring-alerting) on CPU, memory, and disk to be emailed when a threshold is breached — and the platform continuously health-monitors your instances, alerting your team if one crashes or runs out of memory. CPU and memory figures reported inside the VM reflect your instance's real limits, not the host's.

### CPU Usage

Monitor CPU utilization:

**Dashboard**:
- Real-time graph
- Average over 1h, 6h, 24h
- Peak usage highlighted

**SSH Monitoring**:
```bash
# Real-time CPU usage
htop

# CPU info
lscpu

# Load average
uptime

# Per-process CPU
top -o %CPU
```

**High CPU Troubleshooting**:
1. Identify process: `top`
2. Check logs: `journalctl -xe`
3. Restart service if needed
4. Consider upgrading profile

### Memory Usage

Track RAM utilization:

**Dashboard**:
- Used vs. Available
- Swap usage
- Historical trends

**SSH Monitoring**:
```bash
# Memory usage
free -h

# Detailed memory info
cat /proc/meminfo

# Per-process memory
top -o %MEM

# Find memory hogs
ps aux --sort=-%mem | head
```

**High Memory Solutions**:
1. Identify memory leak
2. Restart services
3. Clear caches
4. Upgrade to larger profile

### Disk Usage

Monitor storage utilization:

**Dashboard**:
- Used/Total storage
- I/O operations per second
- Read/write bandwidth

**SSH Monitoring**:
```bash
# Disk space
df -h

# Largest directories
du -h --max-depth=1 /

# Find large files
find / -type f -size +100M -exec ls -lh {} \;

# I/O stats
iostat -x 1
```

**Low Disk Space Solutions**:
```bash
# Clean package cache
apt clean  # Ubuntu/Debian
dnf clean all  # AlmaLinux/Rocky

# Remove old logs
journalctl --vacuum-time=7d

# Find and remove old files
find /tmp -type f -atime +7 -delete

# Docker cleanup (if applicable)
docker system prune -a
```

### Network Traffic

Monitor bandwidth usage:

**Dashboard**:
- Inbound traffic
- Outbound traffic
- Peak bandwidth
- Monthly total

The **traffic visualizer** breaks your VPS traffic down by connection/flow, and inbound connections are enriched with source-reputation data to help you spot suspicious sources. Only public egress counts toward your included traffic quota — traffic to your own resources over the private network is free.

**SSH Monitoring**:
```bash
# Network interfaces
ifconfig

# Live traffic
iftop

# Bandwidth per process
nethogs

# Network statistics
netstat -i
```

## Software Management

### Update System

Keep your system updated:

**Ubuntu/Debian**:
```bash
# Update package list
sudo apt update

# Upgrade packages
sudo apt upgrade -y

# Upgrade distribution
sudo apt dist-upgrade -y

# Remove old packages
sudo apt autoremove -y
```

**AlmaLinux/Rocky/Fedora**:
```bash
# Update all packages
sudo yum update -y

# Or with dnf (Fedora)
sudo dnf update -y

# Clean old packages
sudo yum autoremove -y
```

**Auto-Updates** (Ubuntu/Debian):
```bash
# Install unattended-upgrades
sudo apt install unattended-upgrades -y

# Enable auto-updates
sudo dpkg-reconfigure -plow unattended-upgrades
```

### Install Software

**Web Server**:
```bash
# Nginx
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx

# Apache
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
```

**Database**:
```bash
# MySQL
sudo apt install mysql-server -y
sudo mysql_secure_installation

# PostgreSQL
sudo apt install postgresql postgresql-contrib -y

# Redis
sudo apt install redis-server -y
```

**Programming Languages**:
```bash
# Python 3
sudo apt install python3 python3-pip -y

# Node.js (via NodeSource)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y

# PHP
sudo apt install php php-fpm php-mysql -y

# Go
sudo apt install golang -y

# Ruby
sudo apt install ruby-full -y
```

**Docker**:
```bash
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add user to docker group
sudo usermod -aG docker $USER

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```

### Service Management

Control system services:

```bash
# Start service
sudo systemctl start nginx

# Stop service
sudo systemctl stop nginx

# Restart service
sudo systemctl restart nginx

# Reload configuration
sudo systemctl reload nginx

# Enable on boot
sudo systemctl enable nginx

# Disable on boot
sudo systemctl disable nginx

# Check status
sudo systemctl status nginx

# View logs
sudo journalctl -u nginx -f
```

## User Management

### Create Users

Add non-root users:

```bash
# Create user
sudo adduser johndoe

# Add to sudo group (Ubuntu/Debian)
sudo usermod -aG sudo johndoe

# Add to wheel group (AlmaLinux/Rocky)
sudo usermod -aG wheel johndoe

# Set password
sudo passwd johndoe
```

### SSH Key Management

**Add SSH key for user**:
```bash
# Switch to user
sudo su - johndoe

# Create .ssh directory
mkdir -p ~/.ssh
chmod 700 ~/.ssh

# Add public key
echo "ssh-ed25519 AAAA..." >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
```

**Disable password authentication**:
```bash
# Edit SSH config
sudo nano /etc/ssh/sshd_config

# Set these values:
PasswordAuthentication no
PubkeyAuthentication yes

# Restart SSH
sudo systemctl restart sshd
```

## Security Hardening

### Configure Firewall

**UFW (Ubuntu/Debian)**:
```bash
# Install UFW
sudo apt install ufw -y

# Default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# Allow SSH (important!)
sudo ufw allow 22/tcp

# Allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Enable firewall
sudo ufw enable

# Check status
sudo ufw status verbose
```

**Firewalld (AlmaLinux/Rocky)**:
```bash
# Start firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld

# Allow services
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

# Reload
sudo firewall-cmd --reload

# Check status
sudo firewall-cmd --list-all
```

### Install Fail2Ban

Protect against brute-force attacks:

```bash
# Install
sudo apt install fail2ban -y

# Create local config
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

# Edit config
sudo nano /etc/fail2ban/jail.local

# Find [sshd] section and ensure:
enabled = true
maxretry = 3
bantime = 3600

# Start fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

# Check status
sudo fail2ban-client status sshd
```

### Secure SSH

Best practices for SSH:

```bash
# Edit SSH config
sudo nano /etc/ssh/sshd_config

# Recommended settings:
Port 22                          # Or custom port
PermitRootLogin no              # Disable root login
PasswordAuthentication no        # Key-based only
PubkeyAuthentication yes
PermitEmptyPasswords no
X11Forwarding no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2

# Restart SSH
sudo systemctl restart sshd
```

### Adjust SSH Session Timeout

By default, SSH sessions timeout after 10 minutes of inactivity. You can increase this by editing the SSH configuration:

```bash
# Edit the production SSH config
sudo nano /etc/ssh/sshd_config.d/99-production.conf

# Find and modify these values:
ClientAliveInterval 300    # Seconds between keep-alive checks
ClientAliveCountMax 2      # Number of missed keep-alives before disconnect
```

The total timeout = `ClientAliveInterval × ClientAliveCountMax` seconds.

**Common timeout settings**:

| Timeout | ClientAliveInterval | ClientAliveCountMax |
|---------|---------------------|---------------------|
| 10 min (default) | 300 | 2 |
| 30 min | 900 | 2 |
| 1 hour | 1800 | 2 |
| 4 hours | 3600 | 4 |
| 8 hours | 3600 | 8 |
| Disabled | 0 | 0 |

After editing, restart SSH:

```bash
sudo systemctl restart sshd
```

**Note**: Longer timeouts may pose a security risk if you leave sessions unattended. Consider your security requirements when adjusting this setting.

### Enable Automatic Security Updates

**Ubuntu/Debian**:
```bash
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure -plow unattended-upgrades
```

**AlmaLinux/Rocky**:
```bash
sudo dnf install dnf-automatic -y
sudo systemctl enable --now dnf-automatic.timer
```

## Backup & Recovery

### Create Snapshots

Regular snapshots protect your data:

1. Go to instance dashboard
2. Click **Snapshots** tab
3. Click **Create Snapshot**
4. Enter descriptive name
5. Click **Create**

**Snapshot Tips**:
- Take before major changes
- Weekly for production
- Before system updates
- Label with date and purpose

### Manual Backups

Backup specific data:

**Database Backup**:
```bash
# MySQL
mysqldump -u root -p database_name > backup.sql

# PostgreSQL
pg_dump database_name > backup.sql
```

**File Backup**:
```bash
# Tar archive
tar -czf backup.tar.gz /path/to/data/

# Rsync to remote server
rsync -avz /path/to/data/ user@remote:/backup/
```

**Automated Backups**:
```bash
# Create backup script
cat > /root/backup.sh << 'EOF'
#!/bin/bash
DATE=$(date +%Y%m%d)
tar -czf /backup/data-$DATE.tar.gz /var/www/
find /backup/ -name "data-*.tar.gz" -mtime +7 -delete
EOF

chmod +x /root/backup.sh

# Add to crontab
crontab -e
# Add: 0 2 * * * /root/backup.sh
```

## Performance Optimization

### Optimize Web Server

**Nginx**:
```nginx
# /etc/nginx/nginx.conf
worker_processes auto;
worker_connections 2048;

gzip on;
gzip_types text/plain text/css application/json application/javascript;

client_max_body_size 100M;
```

**PHP-FPM**:
```ini
# /etc/php/8.1/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
```

### Enable Caching

**Redis for sessions**:
```bash
# Install Redis
sudo apt install redis-server -y

# Configure PHP to use Redis
echo "session.save_handler = redis" >> /etc/php/8.1/fpm/php.ini
echo "session.save_path = 'tcp://127.0.0.1:6379'" >> /etc/php/8.1/fpm/php.ini
```

### Database Optimization

**MySQL tuning**:
```sql
-- Check slow queries
SHOW VARIABLES LIKE 'slow_query_log';
SET GLOBAL slow_query_log = 'ON';

-- Add indexes
CREATE INDEX idx_user_email ON users(email);

-- Analyze tables
ANALYZE TABLE users;
```

## Troubleshooting

### Cannot SSH

**Check instance status**:
- Verify instance is running
- Check SSH service: `sudo systemctl status sshd`
- Check firewall allows port 22

**Test connectivity**:
```bash
# Ping server
ping your-ip

# Test SSH port
telnet your-ip 22

# Verbose SSH
ssh -v root@your-ip
```

### High Load

**Check processes**:
```bash
# CPU hogs
top -o %CPU

# Memory hogs
top -o %MEM

# Disk I/O
iotop
```

**Solutions**:
- Kill rogue processes
- Restart services
- Upgrade instance profile
- Optimize applications

### Out of Disk Space

**Find space hogs**:
```bash
du -h --max-depth=1 / | sort -rh | head -20
```

**Clean up**:
```bash
# Old logs
sudo journalctl --vacuum-time=7d

# Package cache
sudo apt clean

# Docker cleanup
docker system prune -a

# Old kernels (Ubuntu)
sudo apt autoremove --purge
```

### Service Won't Start

**Check logs**:
```bash
sudo journalctl -u service-name -n 50

# Or
sudo tail -f /var/log/nginx/error.log
```

**Common fixes**:
```bash
# Check configuration
sudo nginx -t

# Fix permissions
sudo chown -R www-data:www-data /var/www/

# Check ports
sudo netstat -tlnp | grep :80
```

## Best Practices

### Regular Maintenance

**Weekly**:
- [ ] Review resource usage
- [ ] Check for updates
- [ ] Review logs for errors
- [ ] Verify backups

**Monthly**:
- [ ] Full system update
- [ ] Create snapshot
- [ ] Review security logs
- [ ] Clean up old files
- [ ] Review firewall rules

### Monitoring

Set up monitoring:
- CPU/memory alerts
- Disk space alerts
- Service health checks
- Uptime monitoring

### Documentation

Keep records of:
- Configuration changes
- Software installed
- User accounts
- Firewall rules
- Backup schedules

## Next Steps

- [VPS Snapshots Guide](https://docs.danubedata.ro/vps-snapshots)
- [SSH Access Guide](https://docs.danubedata.ro/vps-ssh)
- [Firewall Configuration](https://docs.danubedata.ro/networking-firewalls)
- [Monitoring Setup](https://docs.danubedata.ro/monitoring-overview)

Need help? Contact support through the dashboard.

