Unlock Faster VPS Access



Avoiding complexity and using ~/.ssh/config to streamline VPS management.

Picture of stream

People, mainly companies today fall prey to a variety of unnecessary, bloated, and one-size fits all solutions that in the long run cause headaches.

A great example of this is when managing multiple servers, relying on premium paid IT services to accomplish what can easily be accomplished by a little patience and care instead of letting anxiety pillage managerial decisions.

Shooting sparrows with cannons - The proportional response to a given problem is almost always better than the excessive response.

I hope after highlighting the downsides of overcomplicated solutions you’re on board with me in following the KISS principle, Keep It Simple, Silly.

This principle holds true in managing servers and a variety of digital infrastructure. Instead of relying on cumbersome and usually costly external tools, there’s immense power in leveraging built-in Unix features such as SSH aliases - a simple yet potent tool that exemplifies what I love about Unix based systems.

Let’s dive into SSH aliases and streamlining managing multiple servers

Learn how to streamline VPS management using SSH aliases in ~/.ssh/config

Improve security, efficiency, and simplify remote server access with Unix tools. image of terminal

Some caveats before we begin, We want to ensure safe and stable connections so let’s look at an example here for ~/.ssh/config:

Host DebianServer1
        User Johnnyboy               
        Hostname 192.168.10.41 
        ServerAliveInterval 30 
        ServerAliveCountMax 6  
        Port 2222             

Bad to use User root for your server, if your ssh is compromised so is your server, in the event of multiple users needing access to the same server, do not use user root.

Disabling Root SSH Login (not used in my example but good to know!)

PermitRootLogin prohibit-password

this above can be edited in /etc/ssh/sshd_config and you will have to restart the ssh daemon(service): sudo systemctl restart sshd

I’ve always opted for passwordless ssh using RSA encryption, though ED25519 likely better nowadays. Hostname, can also be domain name if setup here and DNS A-Records set correctly. ServerAliveInterval and ServerAliveCountMax (as shown above) help handle bad networks or spotty internet. Never use standard Port 22, reduces log noise from bots!

But now the real magic happens, using these SSH aliases in shell scripts!

#!/bin/sh

SERVERS="
DebianServer1
UbuntuServer2
RockyNode3
BackupServer4
"

echo "Collecting system health from all servers..."
echo ""

for SERVER in $SERVERS; do
    echo "→ $SERVER"
    ssh "$SERVER" "
        echo -n 'Hostname: '; hostname
        echo -n 'Uptime:   '; uptime -p
        echo -n 'Load:     '; awk '{print \$1, \$2, \$3}' /proc/loadavg
        echo -n 'Memory:   '; free -h | awk '/Mem:/{print \$3 \"/\" \$2}'
        echo -n 'Disk:     '; df -h / | awk 'NR==2 {print \$3 \"/\" \$2}'
        echo ''
    "
done

By configuring your ~/.ssh/config file as shown above, you can significantly streamline your workflow and manage multiple VPS instances with ease. Leveraging SSH aliases not only saves you time but also reduces the complexity and cost associated with external tools. Remember the KISS principle - keeping things simple often leads to more robust and efficient solutions.

To wrap up, here are the key takeaways:

  1. Simplicity over Complexity: Use built-in Unix features to avoid the pitfalls of overcomplicated solutions.
  2. Security: Always opt for secure practices, such as disabling root login and using non-standard ports.
  3. Efficiency: SSH aliases can automate and simplify your server management tasks.