Tutorials

Linux VPS Setup Guide - Complete Tutorial

February 22, 2026
15 min read read
M
Manas

Just got your first Linux VPS? This guide walks you through everything from initial login to running your first application. We will use Ubuntu 22.04 LTS, but most steps apply to other distributions.

Prerequisites

Before starting, you need:

  • VPS with SSH access
  • Root password or SSH key
  • Terminal application (PuTTY on Windows, Terminal on Mac/Linux)

Step 1: First Login

Connect via SSH

ssh root@your_server_ip

You will be prompted for the password provided by your hosting provider.

Update the System

First thing after login, update all packages:

apt update && apt upgrade -y

This ensures you have the latest security patches.

Step 2: Create a Non-Root User

Running as root is dangerous. Create a regular user:

# Create user
adduser myuser

# Add to sudo group
usermod -aG sudo myuser

Test the new user:

su - myuser
sudo whoami  # Should output: root

Step 3: Set Up SSH Keys

SSH keys are more secure than passwords.

On Your Local Machine

Generate a key pair:

ssh-keygen -t ed25519 -C "your_email@example.com"

Copy Key to Server

ssh-copy-id myuser@your_server_ip

Or manually:

# On server as myuser
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
# Paste your public key
chmod 600 ~/.ssh/authorized_keys

Test Key Login

ssh myuser@your_server_ip

Should login without password prompt.

Step 4: Secure SSH

Edit SSH configuration:

sudo nano /etc/ssh/sshd_config

Make these changes:

# Disable root login
PermitRootLogin no

# Disable password authentication
PasswordAuthentication no

# Change default port (optional)
Port 2222

# Allow only your user
AllowUsers myuser

Restart SSH:

sudo systemctl restart sshd

Important: Keep your current session open and test new connection before closing!

Step 5: Configure Firewall

Ubuntu includes UFW (Uncomplicated Firewall):

# Allow SSH (use your port if changed)
sudo ufw allow 2222/tcp

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

# Enable firewall
sudo ufw enable

# Check status
sudo ufw status

Step 6: Install Essential Tools

Basic Utilities

sudo apt install -y \
  curl \
  wget \
  git \
  htop \
  unzip \
  nano \
  fail2ban

Configure Fail2ban

Fail2ban protects against brute force attacks:

sudo systemctl enable fail2ban
sudo systemctl start fail2ban

Step 7: Set Up Automatic Updates

Enable automatic security updates:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Step 8: Install Node.js (Optional)

For running Node.js applications:

# Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

# Verify
node --version
npm --version

Step 9: Install Python (Optional)

Python 3 is usually pre-installed, but ensure pip is available:

sudo apt install -y python3-pip python3-venv

# Verify
python3 --version
pip3 --version

Step 10: Install Docker (Optional)

For containerized applications:

# 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 myuser

# Install Docker Compose
sudo apt install docker-compose-plugin

# Verify
docker --version
docker compose version

Log out and back in for group changes to take effect.

Step 11: Set Up Swap (If Needed)

For VPS with limited RAM, add swap space:

# Check current swap
free -h

# Create 2GB swap file
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# Make permanent
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

# Verify
free -h

Step 12: Configure Timezone

Set your timezone:

# List timezones
timedatectl list-timezones

# Set timezone
sudo timedatectl set-timezone Asia/Kolkata

# Verify
date

Step 13: Set Up Monitoring

Basic Monitoring with htop

htop

Disk Usage

df -h

Memory Usage

free -h

Step 14: Create Your First Application

Example: Simple Node.js App

# Create project directory
mkdir ~/myapp && cd ~/myapp

# Initialize project
npm init -y

# Create simple server
cat > index.js << 'EOF'
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from VPS!');
});

server.listen(3000, () => {
  console.log('Server running on port 3000');
});
EOF

# Run
node index.js

Keep App Running with PM2

# Install PM2
sudo npm install -g pm2

# Start app
pm2 start index.js --name myapp

# Auto-start on reboot
pm2 startup
pm2 save

Security Checklist

Before going live, verify:

  • [ ] Non-root user created
  • [ ] SSH keys configured
  • [ ] Password authentication disabled
  • [ ] Firewall enabled
  • [ ] Fail2ban running
  • [ ] Automatic updates enabled
  • [ ] Unnecessary services disabled

Common Commands Reference

# System info
uname -a
lsb_release -a

# Resource usage
htop
df -h
free -h

# Service management
sudo systemctl status service_name
sudo systemctl restart service_name

# Logs
sudo journalctl -u service_name
sudo tail -f /var/log/syslog

# Network
ip addr
ss -tulpn

Troubleshooting

Cannot Connect via SSH

  • Check if server is running
  • Verify IP address
  • Check firewall rules
  • Try from different network

Permission Denied

  • Verify user permissions
  • Check file ownership
  • Use sudo for system operations

Out of Memory

  • Add swap space
  • Upgrade VPS plan
  • Optimize applications

Conclusion

Your Linux VPS is now set up and secured. From here, you can deploy websites, applications, Discord bots, or any other services. Remember to keep your system updated and monitor resource usage.

HeavenCloud provides high-performance Linux VPS with easy setup, pre-configured security, and locations in India and USA for low latency.

Start building your community

Deploy high-performance Discord bots, Lavalink nodes, and VPS servers with instant setup on HeavenCloud.