Ora

How to Install OpenSSH?

Published in OpenSSH Installation 5 mins read

Installing OpenSSH enables secure remote access and file transfer capabilities on your system, serving as both a client (to connect to other SSH servers) and a server (to allow incoming SSH connections). The installation process varies slightly depending on your operating system.

Installing OpenSSH on Different Operating Systems

OpenSSH is widely available and typically straightforward to install across various platforms.

Windows

On Windows, OpenSSH can be installed via the graphical user interface (GUI) or through the command line using PowerShell.

GUI Method (Windows Settings)

This method is ideal for users who prefer a visual interface for managing features.

  1. Open Settings: Go to Settings on your Windows device.
  2. Navigate to Optional Features: Click on System, then select Optional features (or Optional features directly under Apps & features in older Windows versions).
  3. Check Existing Installation: Review the list of installed features to see if "OpenSSH Client" or "OpenSSH Server" are already present. The client is usually installed by default.
  4. Add OpenSSH Server: If "OpenSSH Server" is not listed, click on Add a feature.
  5. Install OpenSSH Server: In the search bar or list, find and select OpenSSH Server, then click Install.
  6. Confirm Installation: After installation, confirm that "OpenSSH Server" is now listed under your "Optional features."
  7. Configure and Start Service:
    • Open the Services app (you can search for "Services" in the Start Menu).
    • Locate OpenSSH SSH Server in the list.
    • Right-click on it, select Properties.
    • In the "General" tab, set the "Startup type" to Automatic.
    • Click the Start button if the service is not already running.
    • Click Apply and then OK.
  8. Configure Firewall (Important for Server): To allow incoming connections, you must enable the firewall rule. Open Windows Defender Firewall with Advanced Security (search "Firewall" in Start Menu) or use PowerShell:
    New-NetFirewallRule -DisplayName "OpenSSH SSH Server" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow

Command Line Method (PowerShell)

For users comfortable with the command line, PowerShell offers a quick way to manage OpenSSH.

  1. Open PowerShell as Administrator: Search for "PowerShell" in the Start Menu, right-click, and select "Run as administrator."
  2. Check Installation Status: To see if OpenSSH components are installed, run:
    Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

    Look for State : Installed for OpenSSH.Client and OpenSSH.Server.

  3. Install OpenSSH Server: If not installed, run:
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  4. Install OpenSSH Client (if needed):
    Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
  5. Start and Enable OpenSSH Service:
    Start-Service sshd
    Set-Service -Name sshd -StartupType Automatic
  6. Configure Firewall: Allow incoming connections through the firewall:
    New-NetFirewallRule -DisplayName "OpenSSH SSH Server" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow

Linux

OpenSSH is a core component of most Linux distributions and is typically installed via the system's package manager.

Debian/Ubuntu-based Systems (APT)

  1. Update Package Lists:
    sudo apt update
  2. Install OpenSSH Server:
    sudo apt install openssh-server

    The openssh-client is usually installed by default.

  3. Enable and Start Service: The SSH service often starts automatically after installation. To ensure it starts on boot and is running:
    sudo systemctl enable ssh --now

CentOS/RHEL/Fedora-based Systems (YUM/DNF)

  1. Install OpenSSH Server:
    sudo yum install openssh-server openssh-clients # For CentOS/RHEL 7 and older
    # OR
    sudo dnf install openssh-server opensssh-clients # For Fedora, CentOS/RHEL 8 and newer
  2. Enable and Start Service:
    sudo systemctl enable sshd --now
  3. Configure FirewallD (if active):
    sudo firewall-cmd --permanent --add-service=ssh
    sudo firewall-cmd --reload

macOS

macOS includes the OpenSSH client by default. The SSH server component (known as "Remote Login") is integrated into the system settings and can be easily enabled.

  1. Open System Settings: Go to System Settings (or System Preferences in older macOS versions).
  2. Navigate to Sharing: Click on General, then select Sharing.
  3. Enable Remote Login: Find Remote Login in the list and toggle it on.
  4. Configure Users (Optional): By default, "All users" can log in. You can click the "i" icon next to "Remote Login" to specify which users are allowed to connect.

Verifying the Installation

After installing OpenSSH, it's a good practice to verify that the service is running correctly.

  • Windows:
    • Check service status in PowerShell: Get-Service sshd (Status should be Running).
    • Test connection: ssh localhost (You might be prompted to accept the host key).
  • Linux:
    • Check service status: sudo systemctl status ssh (or sshd).
    • Test connection: ssh localhost.
  • macOS:
    • Check service status (after enabling Remote Login): sudo launchctl list | grep ssh
    • Test connection: ssh localhost

Quick Command Reference

Here's a quick reference for common OpenSSH server installation commands:

Operating System Install Command Enable/Start Service Command Firewall Configuration (if needed)
Windows (PowerShell) Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 Start-Service sshd Set-Service -Name sshd -StartupType Automatic New-NetFirewallRule -DisplayName "OpenSSH SSH Server" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow
Ubuntu/Debian sudo apt install openssh-server sudo systemctl enable ssh --now (UFW usually prompts, or sudo ufw allow ssh)
CentOS/RHEL/Fedora sudo dnf install openssh-server sudo systemctl enable sshd --now sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload
macOS (Built-in via System Settings) (Enable "Remote Login" in System Settings > Sharing) (macOS firewall manages this automatically)