Secure V-Server Setup
A step-by-step guide to securely setting up a Linux VPS — from the first SSH connection through hardened authentication to Nginx configuration and GitHub integration. Ideal as a personal reference for all future server setups.
Features
- SSH Key Authentication — Permanently disable password login
- User Management — Create a new user with sudo privileges
- Nginx — Install web server and host a custom HTML page
- Alias Shortcuts — Connect via SSH with a short command
- GitHub SSH Integration — Clone repos directly from the server
Tech Stack
Linux SSH Nginx Bash GitHub
1. Set Up SSH Connection
Generate SSH Key
ssh-keygen -t ed25519
Connect to VPS
ssh root@SERVER-IP
Create New User
adduser username
usermod -aG sudo username
mkdir -p /home/username/.ssh
chmod 700 /home/username/.ssh
chown -R username:username /home/username/.ssh
Copy SSH Key to Server
Windows:
type C:\Users\username\.ssh\id_ed25519.pub | ssh username@SERVER-IP "cat >> .ssh/authorized_keys"
Linux/Mac:
ssh-copy-id -i ~/.ssh/id_ed25519.pub username@SERVER-IP
Set File Permissions
sudo chown username:username /home/username/.ssh/authorized_keys
sudo chmod 600 /home/username/.ssh/authorized_keys
sudo chmod 700 /home/username/.ssh
Disable Password Login
sudo nano /etc/ssh/sshd_config
PasswordAuthentication yes → PasswordAuthentication no (remove comment from line)
sudo systemctl restart ssh.service
warning
From this point on, only SSH key login is possible. Make sure the key works before closing the session.
2. Set Up Nginx
Installation
sudo apt update
sudo apt install nginx -y
systemctl status nginx
Find IP Address
ifconfig
eth0 inet shows the server IP.
Host a Custom HTML Page
sudo mkdir /var/www/alternatives/
sudo touch /var/www/alternatives/alternate-index.html
sudo nano /etc/nginx/sites-enabled/alternatives
Nginx configuration:
server {
listen 8081;
listen [::]:8081;
root /var/www/alternatives;
index alternate-index.html;
location / {
try_files $uri $uri/ =404;
}
}
sudo service nginx restart
3. Create Alias Shortcuts
cd /home/username
sudo nano .bashrc
Define alias:
alias dal_connect='ssh -i ~/.ssh/id_ed25519 username@SERVER-IP'
Activate:
. ~/.bashrc
dal_connect # Now connects directly
4. GitHub SSH Integration
cat /home/username/.ssh/id_ed25519.pub
Add the copied key on GitHub: Settings → SSH and GPG Keys → New SSH Key
What I Learned
- SSH Hardening — Why password login on servers is a security risk and how to disable it
- Linux User Management — Users, groups and file permissions on a real system
- Nginx — Configuring a web server and running multiple sites on different ports
- Bash Aliases — Making repetitive commands more productive with shortcuts