SSH Config and Aliases

ShellBeginner
Practice Now

Introduction

SSH Config (~/.ssh/config) is your server address book.

Instead of typing connection details every time, you can create Aliases (Nicknames).

Example:

  • Before: ssh user@192.168.1.100 -p 2222 ...
  • After: ssh myserver

In this lab, you will configure an alias for your server.

This matters because SSH usage becomes repetitive quickly in real work. A configuration file turns many scattered connection details into a small, reusable address book.

Create Config File

Create the SSH config file using nano.

nano ~/.ssh/config

If it asks for permission or directory doesn't exist, create it first (usually exists).

Wait for next step to add content.

The ~/.ssh directory is one of the most important per-user security directories on a Linux system. It often contains private keys, known hosts, and client configuration.

Add Host Alias

Define the "Nickname" for the server.

In nano ~/.ssh/config, add:

Host labserver

This sets the alias labserver.

Add Connection Details

Add the real connection info under the alias. Indent the lines for readability.

Host labserver
    HostName localhost
    User labuser
  • HostName: The real IP/Domain (localhost).
  • User: The username (labuser).

The alias block lets you separate a human-friendly nickname from the actual technical connection details.

Save and exit (Ctrl+O, Enter, Ctrl+X).

Connect with Alias (ssh labserver)

Test your "Speed Dial".

ssh labserver

It should connect as labuser@localhost automatically.

As SSH setups grow more complex, config files can also store ports, identity files, and other options, which is why this simple aliasing pattern scales well.

Type exit to close.

Summary

In this lab, you built your SSH "Address Book".

  1. Config File: You created ~/.ssh/config.
  2. Aliases: You defined a Host nickname (labserver).
  3. Details: You saved the HostName and User under that alias.
  4. Speed Dial: You connected using just the nickname.

As you work with more servers (AWS, Google Cloud, Company Servers), this file will become your best friend, saving you from remembering dozens of IP addresses and usernames!