How to Enable SSH on Ubuntu: A Quick and Simple Guide

How to Enable SSH on Ubuntu: A Quick and Simple Guide

Photo of author
Written By Eric Sandler

Secure Shell (SSH) is a popular protocol that allows you to securely connect to a remote machine over a network. It’s particularly useful for system administrators and developers who need to manage servers remotely.

By default, Ubuntu doesn’t have SSH enabled, but enabling it is simple. In this guide, we’ll walk you through how to enable SSH on Ubuntu so you can start managing your system remotely.

What Is SSH?

SSH (Secure Shell) is a protocol that provides secure access to a remote system over an unsecured network. It allows you to run commands, transfer files, and manage your system as if you were sitting right in front of it. SSH is encrypted, meaning that all communication between the client and the server is secure.

Steps to Enable SSH on Ubuntu

Step 1: Update Your System

Before you enable SSH, it’s always a good idea to make sure your system is up to date. This ensures that all packages are updated and reduces the likelihood of running into issues.

  1. Open a terminal by pressing Ctrl + Alt + T.
  2. Run the following command to update your system’s package list and upgrade installed packages:
   sudo apt update && sudo apt upgrade

This will ensure your Ubuntu system is up to date before enabling SSH.

Step 2: Install the OpenSSH Server

Ubuntu uses OpenSSH as its default SSH server software. If it’s not already installed, you can install it using the apt package manager.

  1. Install the OpenSSH server package by running the following command:
   sudo apt install openssh-server
  1. After installation, verify that the SSH service is running by using the following command:
   sudo systemctl status ssh

If SSH is running, you should see an output similar to:

● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running)

If the SSH service is not active, you can start it using:

   sudo systemctl start ssh

Step 3: Enable SSH to Start at Boot

To ensure that the SSH server starts automatically every time your Ubuntu system boots up, you need to enable it.

  1. Run the following command to enable SSH on startup:
   sudo systemctl enable ssh

This will ensure SSH starts every time your system boots, making it available for remote connections at any time.

Step 4: Configure Firewall (Optional)

If your Ubuntu system has a firewall enabled, you’ll need to allow SSH traffic. Ubuntu’s default firewall, UFW (Uncomplicated Firewall), can be used to configure this.

  1. To allow SSH through the firewall, run:
   sudo ufw allow ssh
  1. If UFW is not active, you can enable it by typing:
   sudo ufw enable

After configuring the firewall, SSH should be allowed, and you can connect to your Ubuntu system remotely.

Step 5: Find Your System’s IP Address

To connect to your Ubuntu system using SSH from another device, you’ll need to know its IP address.

  1. Run the following command to find your IP address:
   ip a
  1. Look for the network interface that is connected (usually eth0 for wired connections or wlan0 for wireless). You should see your IP address listed under inet.

For example:

inet 192.168.1.100/24

In this case, your IP address is 192.168.1.100.

Step 6: Connect to Your Ubuntu System via SSH

Now that SSH is enabled, you can connect to your Ubuntu system from another computer using an SSH client. Most Linux and macOS systems come with SSH installed by default. For Windows, you can use PuTTY or the built-in Windows Terminal with OpenSSH.

To connect, use the following command:

   ssh username@IP_address

For example, if your username is ubuntuuser and your IP address is 192.168.1.100, you would enter:

   ssh ubuntuuser@192.168.1.100

You will be prompted to enter your password. Once authenticated, you will be connected to your Ubuntu machine.

Additional SSH Configuration (Optional)

After enabling SSH, you may want to adjust the configuration for security or functionality purposes.

  1. Edit the SSH configuration file:
    The SSH server configuration is located at /etc/ssh/sshd_config. You can edit it using any text editor:
   sudo nano /etc/ssh/sshd_config
  1. Change the SSH port (Optional for security):
    For additional security, you can change the default SSH port (which is port 22). In the configuration file, look for the line:
   #Port 22

Change it to any other port number, for example:

   Port 2222
  1. Restart SSH to apply changes:
    After making changes to the configuration, restart the SSH service to apply the changes:
   sudo systemctl restart ssh

Conclusion

Enabling SSH on Ubuntu allows you to securely manage your system remotely, making it a critical tool for system administrators and developers. By following the steps above, you can quickly enable SSH, secure your connection with a firewall, and start managing your Ubuntu system from any location. Whether you’re managing servers or just accessing your machine remotely, SSH is a reliable and secure method for remote access.

Eric Sandler

Leave a Comment