The "ssh_init: host not found" error occurs when SSH cannot resolve the hostname, usually due to:
To bypass DNS resolution issues entirely, try connecting with your server's IP address instead of its hostname.
Windows Command Prompt:
nslookup yourserver.com
Linux/macOS Terminal:
dig yourserver.com +short
or
host yourserver.com
Example Output:
192.168.1.10
Instead of connecting with the hostname:
ssh user@yourserver.com
Try connecting with the IP address:
ssh user@192.168.1.10
Diagnostic Result:
If the hostname is not resolving, check your system's DNS settings directly.
For Windows:
nslookup yourserver.com
For Linux/macOS:
systemd-resolve yourserver.com
or
host yourserver.com
Expected Results:
192.168.1.10), DNS is working correctly from your system's perspective."host not found", "NXDOMAIN", or no IP address appears, DNS is failing and you should move to the next step.If DNS is not resolving the hostname, you can manually map it to its IP address on your local system. This is a reliable workaround that bypasses external DNS entirely.
For Linux/macOS:
sudo nano /etc/hosts
Add this line at the end of the file (use your actual IP and hostname):
192.168.1.10 yourserver.com
Save (Ctrl+O) and exit (Ctrl+X).
For Windows:
C:\Windows\System32\drivers\etc\hosts
192.168.1.10 yourserver.com
Now SSH should recognize the hostname by checking this local file first.
Clear old or corrupted DNS records from your system's cache to force it to retrieve fresh information.
For Windows:
ipconfig /flushdns
For macOS:
sudo killall -HUP mDNSResponder
For Linux (systemd-based distros like Ubuntu, Debian, CentOS 8+):
sudo systemd-resolve --flush-caches
After running the appropriate command for your OS, retry your SSH connection.
Restarting your network interface can refresh all connection settings, including DNS.
Linux/macOS:
sudo systemctl restart networking
or
nmcli networking off && nmcli networking on
Windows:
ipconfig /release
ipconfig /renew
Now try connecting again with SSH.
If DNS is working but SSH still fails, the connection might be blocked by a firewall.
Run one of these diagnostic commands:
nc -zv yourserver.com 22
or
telnet yourserver.com 22
Interpretation:
"Connection refused" or it times out, the SSH port is blocked, the service is not running, or the host is unreachable.For UFW (Ubuntu/Debian) - Run these on your server:
sudo ufw allow 22/tcp
sudo ufw reload
For Firewalld (CentOS/RHEL) - Run these on your server:
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reload
Now try SSH again from your client machine.
Your SSH client may have incorrect settings in its configuration file that are causing the hostname resolution to fail.
nano ~/.ssh/config
Host myserver
HostName yourserver.com
User username
Port 22
IdentityFile ~/.ssh/id_rsa
ssh myserver
Ensure the HostName directive contains the correct, resolvable address.
| Issue | Fix |
|---|---|
| Hostname not resolving (ssh_init: host not found) | Use server IP instead of hostname |
| DNS lookup fails | Test with nslookup or dig, and manually add host to /etc/hosts |
| DNS is outdated | Flush DNS with ipconfig /flushdns (Windows) or systemd-resolve --flush-caches (Linux) |
| Firewall blocking SSH | Open port 22 with ufw allow 22/tcp or firewall-cmd --add-service=ssh --permanent |
| SSH config incorrect | Check ~/.ssh/config and update HostName |
| Network issues | Restart networking with systemctl restart networking |
By systematically following these troubleshooting steps, SSH should work without the "ssh_init: host not found" error!