News & Updates

Enable SSH on Ubuntu Server: Step-by-Step Guide

By Noah Patel 193 Views
enable ssh on ubuntu server
Enable SSH on Ubuntu Server: Step-by-Step Guide

Securing remote access is a fundamental concern for any Ubuntu server deployment, and enabling SSH is the first critical step. This protocol provides a secure channel over an unsecured network, allowing administrators to manage servers efficiently from any location. Without it, performing routine maintenance, troubleshooting issues, or deploying updates would require physical access or less secure methods.

Understanding the SSH Service on Ubuntu

By default, a fresh installation of Ubuntu Server includes the OpenSSH server package, but it is often disabled for security reasons. The service runs in the background, listening for connection attempts on port 22. Understanding its default state helps administrators avoid confusion when they initially try to connect. The package is manageable through standard system tools like `systemctl` and `ufw`.

Verifying SSH Installation Status

Before attempting to enable the service, it is wise to check if the software is already present on the system. You can query the package manager to see if `openssh-server` is installed. This step ensures you are not trying to install an unnecessary package and helps diagnose connection issues later if the software is missing.

Checking with the dpkg Command

Run dpkg -l
grep openssh-server to list the installed SSH packages.

If the output shows `ii openssh-server`, the package is installed but inactive.

If the package is absent, you will need to install it using `sudo apt install openssh-server`.

Starting and Enabling the SSH Daemon

Once the package is confirmed to be installed, the next step is to start the daemon and configure it to launch automatically on boot. This ensures that remote access remains available after server reboots, maintaining administrative control without interruption. The process is straightforward and relies on the `systemd` init system.

Command Line Instructions

To start the service immediately, use: sudo systemctl start ssh .

To enable the service at boot, use: sudo systemctl enable ssh .

To verify the current status, use: sudo systemctl status ssh .

Configuring the Firewall for SSH Access

Allowing traffic through the server's firewall is a crucial step that is sometimes overlooked. If the Uncomplicated Firewall (UFW) is active, it will block incoming connections to port 22 by default. Without this configuration, the SSH client will receive a connection timeout, preventing access entirely.

Setting UFW Rules

Allow SSH traffic with: sudo ufw allow ssh .

For custom ports, specify the number: sudo ufw allow 2222/tcp .

Always ensure the firewall allows your current IP address to prevent accidental lockouts.

Hardening Security Post-Configuration

With SSH enabled, the server is accessible, but it is exposed to automated bot attacks attempting to guess passwords. For production environments, disabling password authentication and using key-based authentication is strongly recommended. This method relies on cryptographic keys rather than memorizable phrases, drastically reducing the risk of brute-force attacks.

Key-Based Authentication Setup

Generate a key pair on your local machine using `ssh-keygen`, then copy the public key to the server using `ssh-copy-id user@server_ip`. Finally, edit the SSH configuration file at `/etc/ssh/sshd_config` to set `PasswordAuthentication no`. Remember to keep your private key secure and never share it.

N

Written by Noah Patel

Noah Patel is a Senior Editor focused on business, technology, and markets. He favors data-backed analysis and plain-language explanations.