How to Enable and Configure SSH on Linux, Windows, and macOS

4 min read
Beginner SSH Linux Windows Remote Access How To

Quick Answer: Ubuntu/Debian: sudo apt install openssh-server -y && sudo systemctl enable --now ssh. CentOS: sudo dnf install openssh-server -y && sudo systemctl enable --now sshd. Then connect: ssh user@ip-address.

Need a VPS? Vultr (free credit), DigitalOcean ($200 free credit), or RackNerd (cheap annual deals).


Linux: Ubuntu/Debian

Install and Enable

# Install OpenSSH server
sudo apt update
sudo apt install openssh-server -y

# Start and enable (auto-start on boot)
sudo systemctl enable --now ssh

# Check status
sudo systemctl status ssh

Allow Through Firewall

# UFW (Ubuntu's default firewall)
sudo ufw allow ssh
# or specifically:
sudo ufw allow 22/tcp

# Check firewall status
sudo ufw status

Test Connection

From another computer:

ssh your-username@your-server-ip
# Example:
ssh [email protected]

Linux: CentOS/RHEL/Fedora

# Install
sudo dnf install openssh-server -y

# Start and enable
sudo systemctl enable --now sshd

# Check status
sudo systemctl status sshd

# Allow through firewall
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

Linux: Arch

sudo pacman -S openssh
sudo systemctl enable --now sshd

Windows 11/10

Enable OpenSSH Server

  1. Open SettingsSystemOptional Features
  2. Click Add a feature
  3. Search for OpenSSH Server
  4. Click Install

Or via PowerShell (admin):

# Install OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Start the service
Start-Service sshd

# Set to auto-start on boot
Set-Service -Name sshd -StartupType 'Automatic'

# Allow through Windows Firewall (usually auto-added)
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Connect to Windows

# From another machine
ssh your-windows-username@your-windows-ip

Default shell is Command Prompt. To use PowerShell:

# On the Windows server, set default shell to PowerShell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

macOS

macOS has SSH client built-in. To enable the SSH server (Remote Login):

Via System Settings

  1. Open System SettingsGeneralSharing
  2. Toggle Remote Login on
  3. Choose "All users" or specific users

Via Terminal

# Enable
sudo systemsetup -setremotelogin on

# Disable
sudo systemsetup -setremotelogin off

# Check status
sudo systemsetup -getremotelogin

Configure SSH Server

The config file is /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

Common Settings

# Change SSH port (default: 22)
Port 2222

# Disable root login
PermitRootLogin no

# Disable password authentication (key-only)
PasswordAuthentication no

# Allow specific users only
AllowUsers sam admin

# Set max authentication attempts
MaxAuthTries 3

# Idle timeout (disconnect after inactivity)
ClientAliveInterval 300
ClientAliveCountMax 2

After changes:

# Test config for errors
sudo sshd -t

# Restart SSH
sudo systemctl restart ssh     # Ubuntu/Debian
sudo systemctl restart sshd    # CentOS/RHEL

Set Up SSH Keys (Key-Based Authentication)

Password login is insecure. Set up SSH keys:

On Your Local Machine

# Generate a key pair
ssh-keygen -t ed25519

# Copy your public key to the server
ssh-copy-id [email protected]

# Now connect without password
ssh [email protected]

Then Disable Password Login

# On the server
sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
sudo systemctl restart ssh

Full guide: SSH Keys Setup


Find Your IP Address

# Linux — local IP
ip addr show | grep "inet " | grep -v 127.0.0.1

# Linux — public IP
curl ifconfig.me

# Windows
ipconfig

# macOS
ifconfig | grep "inet " | grep -v 127.0.0.1

Or use our tool: What's My IP


Troubleshooting

# Check if SSH is running
sudo systemctl status ssh     # Ubuntu
sudo systemctl status sshd    # CentOS

# Check if SSH is listening
ss -tlnp | grep :22

# Test connection with verbose output
ssh -v [email protected]

# Check SSH logs
sudo journalctl -u ssh -f         # Ubuntu
sudo journalctl -u sshd -f        # CentOS
sudo tail -f /var/log/auth.log     # Ubuntu
sudo tail -f /var/log/secure       # CentOS
Problem Fix
Connection refused SSH not running. Install and start it
Connection timed out Firewall blocking port 22. Open it
Permission denied (publickey) Server requires keys. Set up SSH keys
Permission denied (password) Wrong password, or password auth disabled
Host key verification failed Server reinstalled. Run ssh-keygen -R hostname
Port 22 blocked by ISP/network Change SSH to port 443 or 2222
Can SSH locally but not remotely Firewall, NAT, or ISP blocking. Check port forwarding

Check if Port 22 is Open

# From another machine
nc -zv 192.168.1.100 22
# or use our tool: Port Scanner at /tools/port-scanner/

Related Guides

Related Tools