Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

ssh says it could not resolve the hostname

Errorssh: Could not resolve hostname hostname: Temporary failure in name resolution

Short 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.

  • Applies to OpenSSH 9.x, Git Bash on Windows 11, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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) '
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2ssh -G shows hostname equal to the nickname you typedA Host alias has no HostName lineFix
    3. 3The 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. 4The name in the error contains a colon and a number, such as example.com:2222The port was written inside the destinationFix

What does the error look like?

  • ssh: Could not resolve hostname hostname: Temporary failure in name resolution
  • ssh: 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.com

2Fix

Use the real DNS name or the IP address of the server.

ssh deploy@203.0.113.10

3Verify

The connection starts and asks for the host key or logs in.

ssh -v deploy@203.0.113.10 true

Confirmed by man.openbsd.org

Did this fix it?

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/config

2Fix

Add HostName to the block so the alias maps to a real address.

Host myserver
    HostName 203.0.113.10
    User deploy
    Port 22

3Verify

ssh -G now prints the real address on the hostname line.

ssh -G myserver | grep -i '^hostname '

Confirmed by man.openbsd.org

Did this fix it?

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/config

2Fix

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 30

3Verify

Run ssh -G again and confirm the hostname line, then connect.

ssh myserver true

Confirmed by man.openbsd.org

Did this fix it?

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:2222

3Verify

The connection reaches the server on the new port.

ssh -v -p 2222 deploy@example.com true

Confirmed by man.openbsd.org

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.