Quick answer: fix the hostname, not SSH authentication
ssh: Could not resolve hostname means the SSH client could not obtain a usable address for the destination name. Start by checking the exact command and the effective HostName in your SSH configuration. Only then investigate DNS, local hosts entries or your VPN.
This error usually happens before a direct SSH client opens a TCP connection to the destination. Changing SSH passwords, opening port 22 or restarting sshd will not fix an unresolved hostname. For ProxyJump and ProxyCommand connections, identify which hop is resolving the name before drawing that conclusion.
| What you see | What to check first |
|---|---|
Could not resolve hostname server | Command syntax; an accidental literal server target |
ssh production fails | ssh -G production and the Host alias |
| IP connects, name fails | Local DNS, hosts entry, search domain or VPN |
Temporary failure in name resolution | DNS resolver availability or network state |
Lab provenance: the terminal captures below document the original isolated tests. The article was adapted to ShadeTerm on November 28, 2026; no new benchmark run is claimed.
What the error means — and what it does not
For a direct SSH connection, the client first determines its destination using command-line arguments and SSH configuration. The operating system then resolves a name to an address; only after that can a TCP connection, SSH handshake and authentication occur. An unresolved name usually stops the process before TCP.
ssh -F /dev/null -v [email protected]
ssh -F /dev/null -v [email protected] reaches name resolution and stops before any Connecting to [IP] line. The reserved .invalid name prevents this test from relying on a real server.The exact trailing text depends on the operating system and resolver: Linux may report Name or service not known or Temporary failure in name resolution; macOS may say nodename nor servname provided, or not known; Windows OpenSSH may say No such host is known. These messages indicate different name-resolution failures; they are not evidence that an SSH password or private key was rejected.
| Message | Stage | Next investigation |
|---|---|---|
Could not resolve hostname | Name resolution | Syntax, SSH config, resolver |
Connection refused | TCP connection | Listener, port, active firewall reject |
No route to host | Network / TCP | Routing, neighbor reachability, ICMP |
Permission denied (publickey) | SSH authentication | Account, key and server configuration |
A ProxyJump or ProxyCommand setup may delegate a later lookup to another machine. Use ssh -vv to establish whether the client or an intermediate hop produced the error.
1. Check the SSH command and the destination
One of the frequently viewed Ask Ubuntu examples uses ssh root@server 10.0.2.15. The client treats root@server as the destination and the address after it as a remote command, so it tries to resolve the literal name server. The correct form is a single destination argument:
# Wrong: "server" is the target; the IP becomes a remote command
ssh root@server 10.0.2.15
# Correct: IP is the destination
ssh [email protected]
# Wrong: this is not how the SSH port is supplied
ssh [email protected]:2222
# Correct: choose the SSH port with -p
ssh -p 2222 [email protected]A Git SSH remote such as [email protected]:owner/repo.git is a repository URL, not an address to paste directly after the ssh command. To check GitHub SSH authentication separately, use ssh -T [email protected]. For a failure inside Git, inspect git remote -v and resolve the actual remote hostname.
If you have an IP address but not a resolvable name, try ssh user@YOUR_REAL_SERVER_IP. A successful IP connection establishes a name-to-address problem, but it does not identify whether the missing mapping belongs in DNS, SSH config, a VPN or a hosts file.
2. Inspect SSH aliases with ssh -G
An SSH Host entry is a client-side alias, not automatically a DNS record. HostName supplies the actual name or IP that the client will use. An unrecognized alias may be passed to the system resolver literally.
# Example ~/.ssh/config (replace the documentation-only address)
Host production
HostName 192.0.2.10
User deploy
Port 2222
# Linux / macOS: inspect the effective destination
ssh -G production | grep -E "^(hostname|user|port) "Expected settings for the example include hostname 192.0.2.10, user deploy and port 2222. 192.0.2.10 is a reserved documentation address; replace it with a real target before connecting. On Windows PowerShell use ssh -G production | Select-String "^(hostname|user|port) ".
Our lab screenshot uses a separate temporary configuration, so it does not modify the reader’s usual ~/.ssh/config:
# Before: ignore normal SSH config files
ssh -F /dev/null -G labbox 2>/dev/null | grep -E '^(hostname|user|port) '
# After: inspect an isolated lab configuration
ssh -F /tmp/sshflow-alias-config -G labbox 2>/dev/null | grep -E '^(hostname|user|port|identityfile) 'The temporary file maps Host labbox to HostName sshflow-copyid-server, User labuser and Port 2222. A normal application should use the correct SSH config file for its own environment.

ssh -G with -F /dev/null and an isolated config file shows that HostName changes the effective target from the literal alias to the Docker server name. This verifies config selection without opening an SSH connection.If the output says hostname production when you intended an IP or FQDN, inspect the local config file, exact Host pattern and any included files. More specific patterns should come before broad defaults because OpenSSH normally uses the first value obtained for each option. A debugging comparison is ssh -F /dev/null -G production on Unix-like systems; this bypasses the usual config files for that invocation.
OpenSSH-based ssh, scp and sftp generally share SSH configuration. Do not assume an alias breaks in scp by design: inspect the actual host argument, selected config and tool version. See SSH config examples.
3. Check Linux name resolution before editing DNS
getent ahosts uses the Linux name-service lookup mechanism, making it a better first approximation of what native SSH resolves than a DNS-only query. getent hosts is also useful for checking a hosts-file mapping. dig and nslookup are useful comparisons because they do not read the local hosts file directly.
getent ahosts host.example
# If dig is installed, compare DNS results:
dig +short host.example
# Investigate the resolver configuration only if needed:
grep "^hosts:" /etc/nsswitch.conf
cat /etc/resolv.conf
# On systemd-resolved systems:
resolvectl status
203.0.113.10 labonly.invalid added only to the disposable client’s /etc/hosts, getent hosts reads the mapping while dig queries DNS. The documentation-only IP is not a reachable server; the test isolates name resolution.For the illustrated experiment, the client used the disposable mapping 203.0.113.10 labonly.invalid and compared getent hosts labonly.invalid with dig labonly.invalid A +noall +comments +answer. The DNS response status depends on the resolver; the key observation is that dig does not read the local hosts-file entry.
If getent resolves a name that dig cannot, the result may come from /etc/hosts, mDNS or another NSS source. If dig works but getent fails, investigate the system resolver and name-service configuration, not just the public DNS record. Run the commands in the same environment as the failing SSH process—Windows, WSL, Docker containers and remote jump hosts can use different resolvers.
A temporary resolver failure is not the same as proof that a DNS record does not exist. On a system managed by NetworkManager, DHCP or systemd-resolved, do not overwrite /etc/resolv.conf blindly: it may be generated.
4. Verify /etc/hosts and prove the fix
A local hosts file maps a name to an address without requiring a DNS record. Inspect it on the client running SSH, not only on the SSH server. On Linux and macOS the file is /etc/hosts; on Windows it is C:\Windows\System32\drivers\etc\hosts.
# Linux / macOS — read only
grep -n "host.example" /etc/hosts
# Example of the format (DO NOT paste this documentation IP as a real host):
192.0.2.10 host.exampleAdd or edit an entry only when you know the correct address and have permission to change local name mappings. The first field is the IP; names follow it. If you are repairing an existing mapping, keep a backup and avoid deleting unrelated entries.

labfix-sshflow.invalid; adding the real Docker server address to the disposable client’s hosts file allows a new SSH connection to proceed to the test account. The successful account and hostname output distinguishes a working connection from a lookup-only fix.The before/after capture uses labfix-sshflow.invalid. First, the client attempts SSH and receives a hostname lookup failure. We then resolve sshflow-copyid-server inside the Docker network, append its returned address to the test client’s /etc/hosts, and retry with the already-authorized lab key. The final whoami; hostname output verifies access beyond name resolution. A resolved hostname alone does not prove the destination is reachable.
A stale hosts entry pointing to the wrong address usually causes a different symptom—connection to the wrong machine, refusal, timeout or a host-key warning—not a missing-name error. Never bypass host-key verification to hide such a mismatch.
5. Windows PowerShell and macOS checks
Windows 10/11 (PowerShell)
ssh -G myserver | Select-String "^(hostname|user|port) "
Resolve-DnsName -Name myserver
# Compare DNS without local hosts-file influence:
Resolve-DnsName -Name myserver -DnsOnly -NoHostsFile
# The DNS server being used by each network adapter:
Get-DnsClientServerAddressWindows name resolution can use hosts-file entries, caches and local network mechanisms. A lookup with -NoHostsFile -DnsOnly is deliberately different from the default lookup; do not assume the two should return identical results. nslookup can also query a specific DNS server but is not a full test of all Windows local name-resolution paths.
macOS
ssh -G myserver | grep -E "^(hostname|user|port) "
dscacheutil -q host -a name myserver
scutil --dnsA local device may be advertised as raspberrypi.local through multicast DNS. This generally depends on local network support and does not imply that the same name should work across the public internet or through every VPN. An IP address, an mDNS name and an internet-facing DNS name solve different problems.
6. VPNs, search domains and SSH jump hosts
A short name such as db01 may depend on an organization-provided DNS search suffix, while db01.internal.example may require a VPN-only DNS resolver. If the connection succeeds on the company network and fails off-VPN, inspect the network-specific DNS settings before changing public DNS servers.
On Linux systems using systemd-resolved, resolvectl status can show which DNS servers and search/routing domains are assigned to interfaces. For Docker clients, inspect name resolution inside the container rather than assuming it uses the Windows host resolver. For WSL, check resolution inside the WSL distribution.
For a jump-host setup such as ssh -J bastion private-host, separate the names and network contexts. The target may be resolved from the bastion side, not by the local laptop. This is a case where the statement “nothing ever contacted an SSH server” can be false. Consult SSH jump host when that is your actual topology.
Do not disable SSH host-key checking, randomly switch DNS to 8.8.8.8, open a firewall port, or restart the SSH daemon until your diagnostics identify the failing stage. Public resolvers generally cannot resolve private VPN-only records.
ShadeTerm lab: controlled hostname-resolution experiments
Test environment. Windows Docker Desktop running two containers on a private Docker network: a debian:bookworm-slim SSH client and a LinuxServer OpenSSH server named sshflow-copyid-server. The Debian package output recorded openssh-client 1:9.2p1-2+deb12u10. The SSH service listens on port 2222 in the Docker network; the Windows host binds the published port 2223 to 127.0.0.1. Tests use a disposable labuser account and a lab-only Ed25519 key.
What we changed. We used temporary SSH configuration and local name mappings inside the Debian client container. We did not change a real DNS zone, disable DNS security, or modify an external VPS. Each of the four terminal screenshots in the article corresponds to one experiment below. The screenshots are evidence for these specific conditions, not proof that every OS or resolver produces identical wording.
| Experiment | Variable changed | What the result demonstrates |
|---|---|---|
| 1. Unknown name | Unresolvable labbox.invalid, with SSH config bypassed | Failure occurs before a destination IP is available |
| 2. SSH alias | -F /dev/null versus a temporary Host labbox configuration | ssh -G reveals which HostName the client will use |
| 3. Local versus DNS lookup | Test-only /etc/hosts entry for labonly.invalid | getent and dig consult different resolution paths |
| 4. Before/after SSH | Add the Docker server IP for labfix-sshflow.invalid | A successful hostname mapping allows an authenticated SSH connection |
Reproduce the negative control and alias test
# Inside the disposable Debian client container
ssh -F /dev/null -v [email protected]
ssh -F /dev/null -G labbox | grep -E '^(hostname|user|port) '
cat > /tmp/sshflow-alias-config <<'EOF'
Host labbox
HostName sshflow-copyid-server
User labuser
Port 2222
IdentityFile ~/.ssh/sshflow_lab_key
EOF
ssh -F /tmp/sshflow-alias-config -G labbox | grep -E '^(hostname|user|port|identityfile) '
Reproduce the hosts-file comparison
# Disposable container only; use reserved documentation names
printf '203.0.113.10 labonly.invalid\n' >> /etc/hosts
getent hosts labonly.invalid
dig labonly.invalid A +noall +comments +answer
The 203.0.113.10 address is in the reserved TEST-NET-3 range. It demonstrates a resolver mapping and must not be treated as an actual server IP. The DNS status may differ across resolvers; the important difference is that the hosts-file name is available to the local resolver but is not automatically a DNS record.
Reproduce the before/after SSH connection
# Requires the lab server and an authorized test key
ssh -F /dev/null -p 2222 [email protected]
SERVER_IP=$(getent ahostsv4 sshflow-copyid-server | awk 'NR==1{print $1}')
printf '%s labfix-sshflow.invalid\n' "$SERVER_IP" >> /etc/hosts
getent hosts labfix-sshflow.invalid
ssh -F /dev/null -p 2222 -i ~/.ssh/sshflow_lab_key \
-o IdentitiesOnly=yes -o BatchMode=yes \
-o StrictHostKeyChecking=accept-new \
[email protected] 'whoami; hostname'
Security and limitations. StrictHostKeyChecking=accept-new is used here only for the new host alias in a disposable, isolated SSH lab. For an actual server, verify its host-key fingerprint independently before trusting a new connection. These four captures evaluate Debian client behavior, not Windows DNS resolution or macOS mDNS. No public DNS records or production permissions were changed.
For test-server setup details, see the LinuxServer OpenSSH container documentation, and for the underlying behavior consult the OpenSSH and getent manuals in Technical references.
Common cases and FAQ
Why does ssh user@IP work but ssh user@hostname fail?
SSH reached a known address in the first case, but your client could not translate the name in the second. Check local name mapping, the correct DNS zone, search suffix and VPN. This distinction appears in real Windows-to-Debian and macOS-to-Raspberry Pi troubleshooting discussions.
Does ssh: Could not resolve hostname mean the server is down?
Not on its own. For a direct connection, an unresolved name prevents reaching the server. The server could be healthy and reachable by IP.
Can a hosts entry override a DNS record?
Often yes, depending on operating-system resolver order. A stale entry can map the right name to the wrong address. Compare system lookup output with a direct DNS query.
Does changing port 22 or SSH keys fix it?
No, not for an unresolved direct destination. The name-resolution stage precedes the TCP port connection and SSH authentication. Check the hostname first. For ProxyJump connections, identify whether the local computer or jump host is resolving the name.
Is it a Git problem?
Git over SSH uses an SSH transport; the error still concerns resolution of the SSH destination, although the hostname may come from the Git remote URL. Inspect git remote -v, and then inspect effective SSH configuration and system name resolution.
Technical references and community cases
Primary documentation for the commands and resolver behavior:
- OpenSSH ssh(1) — -G, -F, verbose output and destination syntax
- OpenSSH ssh_config(5) — Host, HostName, precedence and ProxyJump
- Linux getent(1) — Name Service Switch and ahosts
- getaddrinfo(3) — EAI_NONAME and EAI_AGAIN
- Microsoft Learn — Resolve-DnsName
- Microsoft Learn — DNS client troubleshooting and hosts-file precedence
Real-world user cases behind the diagnostic flow:
Conclusion
The most efficient order is check the command → inspect ssh -G → test the system resolver → compare DNS and local hosts → verify the result with ssh -v. Do not jump to changing firewall rules, server ports or SSH keys when the client cannot resolve a direct destination.
Once the destination is correct, keep your SSH hosts organized with SSH client configuration and ShadeTerm workspaces.