SSH Configuration File: Simplifying Server Access
The SSH configuration file eliminates the need to remember complex login commands, multiple IP addresses, usernames, and key file paths. Instead, you can use simple aliases to connect to your servers.
The Traditional SSH Login Method
Without a configuration file, logging into a server using SSH key authentication requires a lengthy command:
ssh -i /path/to/private/key username@server_ip_address
This approach becomes problematic when managing multiple servers. You must remember:
- Different IP addresses for each server
- Various usernames across servers
- Multiple private key file names and locations
The Solution: SSH Config File
With a properly configured SSH config file, you can simplify your login to:
ssh alias_name
Login Comparison Diagram
Creating the SSH Config File
Step 1: Navigate to your home directory and create the config file
cd ~nano ~/.ssh/config
SSH Config File Variables
Example Configuration: Single Server
Host 240
HostName 192.168.1.100
User andrew
IdentityFile ~/.ssh/my_private_key
ServerAliveInterval 60
ServerAliveCountMax 120
Example Configuration: Multiple Servers
Host 240
HostName 192.168.1.100
User andrew
IdentityFile ~/.ssh/my_private_key
ServerAliveInterval 60
ServerAliveCountMax 120
Host uk
HostName 203.0.113.50
User admin
IdentityFile ~/.ssh/uk_server_key
ServerAliveInterval 60
ServerAliveCountMax 120
Host production
HostName 198.51.100.75
User webmaster
IdentityFile ~/.ssh/prod_key
ServerAliveInterval 60
ServerAliveCountMax 120
After creating the config file, you can connect using:
ssh 240You'll only need to enter your private key passphrase, and you're connected!
Understanding ServerAlive Settings
Connection Keepalive Process
No data received
keepalive message
120 times
disconnection
These settings prevent automatic disconnection after periods of inactivity
Ubuntu Package Management with APT
Understanding APT Commands
Package management in Ubuntu is performed using the APT (Advanced Package Tool) package manager. All
package management commands require administrative privileges, so they must be prefixed with
sudo.
| Command | Purpose | What It Does |
|---|---|---|
sudo apt update |
Refresh package list | Downloads the latest package information from repositories. Does NOT install or upgrade packages. |
sudo apt upgrade |
Install updates | Installs newer versions of currently installed packages. Must run 'update' first. |
sudo apt autoremove |
Clean up | Removes unnecessary packages that are no longer needed as dependencies. |
The Proper Update Sequence
Package Update Workflow
sudo apt update
sudo apt upgrade
sudo apt autoremove
Step-by-Step Update Process
Step 1: Update the Package List
sudo apt update
Example output: "34 packages can be upgraded"
Step 2: Upgrade Packages
sudo apt upgrade
The system will show you:
- Which packages will be installed
- Which packages will be upgraded
- How much disk space will be used
- A prompt asking: "Do you want to continue? [Y/n]"
Step 3: Remove Obsolete Packages
sudo apt autoremove
Handling Configuration File Prompts
Best Practice Answer: N (No)
Why? Answering "Y" (Yes) will overwrite your custom configurations with default settings, losing all your customizations. Always answer "N" (No) to preserve your existing configuration.
Understanding "Kept Back" Updates
If you see a message about updates being "kept back," this is usually due to:
- Dependency Issues: The update conflicts with current package versions
- Phased Rollouts: Ubuntu releases some updates gradually to detect issues early
Action Required: Do NOT force these updates. They will be automatically resolved over time.
Kernel Updates and Rebooting
After certain high-level updates (especially kernel updates), you'll see a notification:
*** System restart required ***
Currently running kernel version is not the expected kernel version.
Restarting the system to load the new kernel will not be handled automatically.
When to Reboot:
- After the first time running updates on a new server (recommended)
- When explicitly notified that a system restart is required
- After kernel updates
sudo reboot
Wait a few minutes for the server to restart, then log back in.
Best Practices for Package Management
- Run the complete update sequence at least 3 times per week
- Always run in order: update → upgrade → autoremove
- Never interrupt the upgrade process
- Always answer "N" to configuration file overwrite prompts
- Reboot when notified after kernel updates
- Don't force "kept back" updates
Complete Update Example
# Step 1: Update package list
sudo apt update
# Step 2: Upgrade packages
sudo apt upgrade
# Step 3: Remove obsolete packages
sudo apt autoremove
# Step 4: Reboot if necessary (first time or after kernel update)
sudo reboot
Monthly Update Timeline Example
Week 1: Monday, Wednesday, Friday - Run full update sequence
Week 2: Monday, Wednesday, Friday - Run full update sequence
Week 3: Monday, Wednesday, Friday - Run full update sequence
Week 4: Monday, Wednesday, Friday - Run full update sequence
Quick Reference Summary
SSH Config File Template
Host your_alias
HostName your_server_ip
User your_username
IdentityFile ~/.ssh/your_private_key
ServerAliveInterval 60
ServerAliveCountMax 120
Essential Update Commands
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo reboot # (if required)
Critical Reminders
- Keep your server updated 3+ times weekly
- Never interrupt package upgrades
- Always preserve existing config files (answer "N")
- Use SSH config for simplified, secure access
- Reboot after significant updates when prompted