ssh says it could not resolve the hostname
ssh: Could not resolve hostname hostname: Temporary failure in name resolutionShort answer
ssh could not turn the name you gave into an address. Run ssh -G with the same name to see the host it will really use. The usual faults are a placeholder or typo in the name, a Host alias with no HostName, a config block that never matches, or a port written inside the destination.
Fix it fast
1Find out which cause you have
Print the effective settings for the exact name you typed. The hostname line shows what ssh will try to look up.
ssh -G myserver | grep -i -E '^(hostname|user|port) '2Match what you see, then jump to its fix
- 1
The name in the error is the literal word from a tutorial, such as hostname or your-serverThe name is a placeholder or a typoFix - 2
ssh -G shows hostname equal to the nickname you typedA Host alias has no HostName lineFix - 3
The alias is in the file, but ssh -G still shows the alias as hostnameThe config block does not match, or an earlier block winsFix - 4
The name in the error contains a colon and a number, such as example.com:2222The port was written inside the destinationFix
- 1
What does the error look like?
ssh: Could not resolve hostname hostname: Temporary failure in name resolutionssh: Could not resolve hostname
Cause 1 of 4
The name is a placeholder or a typo
1Check
The destination is [user@]hostname or ssh://[user@]hostname[:port]. Whatever comes after the user part is looked up as is. Compare it with the real server name.
ssh -G user@hostname | grep -i '^hostname '
getent hosts example.com2Fix
Use the real DNS name or the IP address of the server.
ssh deploy@203.0.113.103Verify
The connection starts and asks for the host key or logs in.
ssh -v deploy@203.0.113.10 trueConfirmed by man.openbsd.org
Cause 2 of 4
A Host alias has no HostName line
1Check
Without a HostName, the default is the name given on the command line, so a nickname is looked up in DNS. Open your config and find the block.
grep -n -A4 -i '^Host ' ~/.ssh/config2Fix
Add HostName to the block so the alias maps to a real address.
Host myserver
HostName 203.0.113.10
User deploy
Port 223Verify
ssh -G now prints the real address on the hostname line.
ssh -G myserver | grep -i '^hostname 'Confirmed by man.openbsd.org
Cause 3 of 4
The config block does not match, or an earlier block wins
1Check
Host takes patterns and a ! negation can switch a whole block off. ssh uses the first value it finds for each setting, so an earlier block can shadow a later one.
ssh -G myserver | head -5
ls -la ~/.ssh/config2Fix
Put the specific Host block above any Host * block, and remove patterns that exclude the name.
Host myserver
HostName 203.0.113.10
Host *
ServerAliveInterval 303Verify
Run ssh -G again and confirm the hostname line, then connect.
ssh myserver trueConfirmed by man.openbsd.org
Cause 4 of 4
The port was written inside the destination
1Check
The documented destination forms are [user@]hostname and ssh://[user@]hostname[:port]. A bare host:port is neither, so the whole string is used as the name. The port belongs in -p or in the URI.
ssh -G deploy@example.com:2222 | grep -i '^hostname '2Fix
Pass the port with -p, or use the URI form.
ssh -p 2222 deploy@example.com
ssh ssh://deploy@example.com:22223Verify
The connection reaches the server on the new port.
ssh -v -p 2222 deploy@example.com trueConfirmed by man.openbsd.org
How do I stop it coming back?
- Give every server a Host block with HostName, User and Port, and connect by the alias.
- Run ssh -G name after editing the config; it shows the result without connecting.
- Keep specific Host blocks above Host * defaults.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
2 causes, each with a fixServers
bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
The shell was told to use a locale that is not built on the server.
3 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fixServers
ping is missing inside a Docker container
sh: 1: ping: not found
Base images such as ubuntu are minimal, so ping is simply not installed.
2 causes, each with a fixServers
Running ps inside a container says command not found
bash: ps: command not found
Slim Debian and Ubuntu images do not ship the procps package, and ps comes from procps.
2 causes, each with a fixServers
GitHub Actions step fails writing to GITHUB_OUTPUT
Error: Invalid format '...'
The runner reads GITHUB_OUTPUT line by line, and every entry must be name=value or a name<<DELIMITER block.
3 causes, each with a fix