Unlock Faster VPS Access







linux



Harnessing the power of ~.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

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.411 
        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 needed access to the same server, do not use user root.

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

PermitRootLogin no

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 always opt for passwordless ssh using RSA encryption. Hostname*, can also be domain name if setup here and DNS A-Records set correctly. Keepalive messages over period of 180 seconds given the 30 second interval we set above help maintain connection if in a place with spotty internet. Never use standard Port 22, big target!

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


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

Host UbuntuServer2
    User Dannyboy
    Hostname 192.168.10.412
    ServerAliveInterval 30
    ServerAliveCountMax 6 
    Port 1776  #just make sure it's a high port not in use by any service

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.