The simplest method is using the package manager:
# For Debian/Ubuntu
dpkg -l | grep openssh-server
# For RHEL/CentOS
rpm -qa | grep openssh-server
Use systemctl to verify if SSH daemon is running:
systemctl status sshd
# or
service sshd status
Active status should show "active (running)" with the listening port (usually 22).
Check if SSH port is listening:
ss -tulnp | grep ssh
# Alternative:
netstat -tulnp | grep ssh
# Or using lsof:
lsof -i :22
From a remote machine, try to connect:
ssh username@server_ip -v
The -v
flag provides verbose output showing connection steps.
Inspect the main configuration file:
cat /etc/ssh/sshd_config | grep -v "^#" | grep -v "^$"
Key parameters to verify:
Port 22
Protocol 2
PermitRootLogin no
PasswordAuthentication yes
If SSH isn't working:
# Check firewall rules
sudo ufw status
sudo iptables -L
# Verify SElinux context (for RHEL systems)
sestatus | grep "Current mode"
# Check logs for errors
journalctl -u sshd --no-pager -n 50
tail -50 /var/log/auth.log
Here's a bash script to perform comprehensive checks:
#!/bin/bash
echo "=== SSH Service Check ==="
systemctl is-active sshd && echo "SSH is running" || echo "SSH NOT running"
echo "\n=== Port Check ==="
ss -tulnp | grep -E ':22|:ssh'
echo "\n=== Configuration Check ==="
grep -E '^Port |^PermitRootLogin |^PasswordAuthentication ' /etc/ssh/sshd_config
echo "\n=== Test Connection ==="
timeout 3 bash -c "
To determine if SSH is running on your server, try these immediate checks:
# Check SSH service status
sudo systemctl status ssh
# Alternative for older systems
service ssh status
SSH typically runs on port 22. Verify with:
# Check if port 22 is listening
netstat -tuln | grep :22
# Or using ss command
ss -tuln | grep :22
Attempt to connect to your own server:
ssh localhost
If you get a connection refused error, SSH might not be running or properly configured.
Check if OpenSSH is installed:
# For Debian/Ubuntu
dpkg -l | grep openssh-server
# For RHEL/CentOS
rpm -qa | grep openssh-server
Examine the SSH configuration:
# View main config file
cat /etc/ssh/sshd_config | grep -v "^#" | grep -v "^$"
Sometimes SSH is running but blocked by firewall:
# Check firewall rules
sudo iptables -L
sudo ufw status
From another machine, try:
telnet your_server_ip 22
You should see an SSH banner if the service is running.
If SSH isn't working:
# Install OpenSSH (Ubuntu/Debian)
sudo apt install openssh-server
# Start the service
sudo systemctl start ssh
sudo systemctl enable ssh