How To Set Up A Linux Server – Secure Remote Access Configuration

Setting up a Linux server begins with choosing between Ubuntu Server, CentOS, or Debian based on your workload requirements. This guide walks you through every step of how to set up a linux server from scratch, whether you are hosting a website, running applications, or learning system administration.

You don’t need to be a command-line expert to get started. With a clear plan and some patience, you can have a fully functional server running in under an hour.

How To Set Up A Linux Server

Before you begin, gather the basics: a computer or virtual machine, a stable internet connection, and a USB drive if installing on bare metal. This process works for most major distributions.

Choose Your Linux Distribution

Your choice of distribution affects package management, security updates, and community support. Here are the three most common options:

  • Ubuntu Server – User-friendly, huge community, great for beginners
  • CentOS Stream – Stable, enterprise-focused, good for production
  • Debian – Rock-solid stability, minimal bloat, ideal for experienced users

For this tutorial, we will use Ubuntu Server 22.04 LTS. It offers long-term support and extensive documentation.

Download And Create Installation Media

Go to the official Ubuntu website and download the server ISO file. Use a tool like Rufus (Windows) or balenaEtcher (macOS/Linux) to write the ISO to a USB drive.

  1. Insert a USB drive with at least 4GB capacity
  2. Open your flashing tool and select the downloaded ISO
  3. Choose the USB drive as the target
  4. Click “Flash” or “Write” and wait for completion

Boot your server hardware from the USB drive. You may need to press F12, F2, or Del during startup to access the boot menu.

Install The Operating System

Once the installer loads, follow these steps:

  1. Select your language and keyboard layout
  2. Choose “Install Ubuntu Server”
  3. Configure network settings – DHCP is fine for most setups
  4. Set up storage – use “Use Entire Disk” for simplicity
  5. Create a user account with a strong password
  6. Install OpenSSH server when prompted (essential for remote access)
  7. Complete the installation and reboot

After reboot, log in with the username and password you created. You will see a command-line interface – this is your server.

Initial Server Configuration

Now that the system is running, you need to secure and prepare it for use. Run these commands as root or with sudo.

Update System Packages

Always start with a full system update:

sudo apt update && sudo apt upgrade -y

This ensures you have the latest security patches and software versions. Repeat this step regularly.

Set A Static IP Address

For a server, a static IP prevents address changes after reboot. Edit the netplan configuration file:

sudo nano /etc/netplan/00-installer-config.yaml

Replace the DHCP line with static settings:

network:
  ethernets:
    ens33:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  version: 2

Apply the changes with sudo netplan apply. Verify with ip a.

Configure Hostname

Set a meaningful hostname for your server:

sudo hostnamectl set-hostname myserver

Edit /etc/hosts to add the hostname mapping:

127.0.0.1 localhost
192.168.1.100 myserver

Secure Your Server

Security is not optional. Follow these steps to harden your Linux server.

Create A Sudo User

If you used the root account during installation, create a regular user with sudo privileges:

sudo adduser yourusername
sudo usermod -aG sudo yourusername

Log out and log back in as this user for daily operations.

Disable Root Login Over SSH

Edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config

Find the line PermitRootLogin yes and change it to no. Save and restart SSH:

sudo systemctl restart ssh

Set Up A Firewall

UFW (Uncomplicated Firewall) makes firewall management easy:

sudo ufw allow OpenSSH
sudo ufw enable

Check status with sudo ufw status. Only allow ports you need.

Enable Automatic Security Updates

Install unattended-upgrades:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

Select “Yes” when prompted. Your server will now install critical updates automatically.

Install Essential Software

Depending on your server’s purpose, you will need different packages. Here are common tools.

Web Server (Apache Or Nginx)

For a web server, install Apache:

sudo apt install apache2 -y

Or Nginx for better performance:

sudo apt install nginx -y

Both will start automatically. Test by visiting your server’s IP in a browser.

Database Server (MySQL Or PostgreSQL)

Install MySQL:

sudo apt install mysql-server -y
sudo mysql_secure_installation

Follow the prompts to set a root password and remove insecure defaults.

Programming Languages

Install Python, Node.js, or PHP as needed:

sudo apt install python3 python3-pip
sudo apt install nodejs npm
sudo apt install php libapache2-mod-php

Set Up Remote Access

You will likely manage your server remotely. SSH is the standard method.

SSH Key Authentication

Generate an SSH key pair on your local machine:

ssh-keygen -t rsa -b 4096

Copy the public key to your server:

ssh-copy-id yourusername@server-ip

Now disable password authentication in /etc/ssh/sshd_config:

PasswordAuthentication no

Restart SSH again. Only key-based logins are allowed.

Use A Terminal Multiplexer

Install tmux or screen to keep sessions alive even if you disconnect:

sudo apt install tmux -y

Start a session with tmux new -s mysession. Detach with Ctrl+B, D, reattach with tmux attach -t mysession.

Monitor System Resources

Keep an eye on CPU, memory, and disk usage. Use these commands:

  • top or htop – real-time process monitoring
  • df -h – disk space usage
  • free -m – memory usage
  • netstat -tuln – listening ports

Install htop for a nicer interface:

sudo apt install htop -y

Backup Your Server

Regular backups prevent data loss. Use rsync for simple file backups:

sudo rsync -avz /var/www/ backupuser@backup-server:/backups/

Automate with cron jobs. Edit the crontab:

crontab -e

Add a line to run daily at 2 AM:

0 2 * * * rsync -avz /var/www/ backupuser@backup-server:/backups/

Troubleshooting Common Issues

Even with careful setup, problems occur. Here are fixes for frequent issues.

Cannot Connect Via SSH

Check if SSH service is running:

sudo systemctl status ssh

Verify firewall allows port 22:

sudo ufw status

Ensure the SSH port is not blocked by your network or ISP.

Server Not Reachable

Ping the server IP from another machine. If it fails, check network configuration and cable connections.

Package Installation Fails

Run sudo apt update again. Sometimes repositories are temporarily unavailable.

Optimize Performance

Fine-tune your server for better speed and reliability.

Disable Unnecessary Services

List running services:

systemctl list-units --type=service --state=running

Stop and disable any you don’t need:

sudo systemctl stop cups
sudo systemctl disable cups

Adjust Swap Usage

If your server has limited RAM, increase swap space:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Add to /etc/fstab for persistence:

/swapfile none swap sw 0 0

Advanced Configuration

Once basics are covered, explore these advanced topics.

Set Up A Virtual Host

For Apache, create a virtual host configuration file:

sudo nano /etc/apache2/sites-available/example.com.conf

Add basic settings and enable it:

sudo a2ensite example.com
sudo systemctl reload apache2

Install A Control Panel

If you prefer a web interface, consider Webmin or Cockpit:

sudo apt install cockpit -y

Access it via https://server-ip:9090.

FAQ: Common Questions About Linux Server Setup

What is the easiest way to set up a Linux server?

Ubuntu Server is the most beginner-friendly. Its installer guides you through partitions, user creation, and SSH setup. Follow the steps above for a smooth experience.

Do I need a static IP for my Linux server?

Yes, a static IP ensures your server always has the same address. This is critical for web hosting, SSH access, and other services that rely on consistent connectivity.

How do I secure a Linux server after installation?

Disable root login, use SSH keys instead of passwords, enable a firewall, and install automatic security updates. These steps block most common attacks.

Can I set up a Linux server on a virtual machine?

Absolutely. VirtualBox, VMware, or cloud providers like AWS and DigitalOcean work well. The installation process is identical to physical hardware.

What should I do if I forget the root password?

Reboot the server and enter recovery mode from the GRUB menu. You can reset the password from there. Alternatively, use a live USB to mount the filesystem and edit the shadow file.

Setting up a Linux server is a rewarding skill that opens doors to hosting, development, and system administration. Start with a simple configuration, then expand as you learn. The command line may feel intimidating at first, but each command you run builds confidence. Keep your system updated, monitor logs regularly, and never skip backups. With practice, you will manage multiple servers with ease.