When trying to ssh from terminal into my raspberry pi using: ssh [email protected] the connection just hangs forever.

When I ping [email protected], I get ping: cannot resolve [email protected]: Unknown host

I can ping and ssh with the ip address just fine using: ssh [email protected]

Not sure if I need to configure my laptop network settings (macOS) or the raspberry pi settings (Debian) to be able to connect via hostname.

  • where are you sshing from ? from pi to pi ? (that's should be OK) from mac to pi ? you should use pi's hostname or IP. can you ssh [email protected] ?
    – Archemar
    May 2, 2023 at 12:54
  • 2
    ping should be used with an IP address or a resolvable name. Inserting a username [email protected] would not be expected to work. May 2, 2023 at 13:00
  • 1
    possibly related: en.wikipedia.org/wiki/.local (mDNS ...)
    – A.B
    May 2, 2023 at 13:03
  • @Archemar ssh-ing from Mac to pi. ssh [email protected] does work, so does ssh 192.168.xxx.xxx.
    – Jet59black
    May 2, 2023 at 13:36
  • 1
    Not sure why this was downvoted. It is a legit question and @bakunin gave a legit explanation and solution below.
    – Jet59black
    May 2, 2023 at 14:11

1 Answer 1


When you give a host a hostname, only this host knows about it. Any other host doesn't know the hostname (and the IP address it corresponds to) at all. A little different are name services (like DNS, NIS, ...), which "distribute" this knowledge across a network. But for our purposes only the host himself knows its hostname.

Having said this: you want to connect from a system (let us call it "yourpc") to another system ("pi"). For this to work "yourpc" has to know which IP address corresponds to this name "pi". In absence of any name service there is one way to enlighten "yourpc", which is: enter the hostname and its corresponding IP address to the file /etc/hosts. In fact this is the specific purpose of this file.

A typical /etc/hosts file looks like this:

# Place comments after octothorpe signs, like in shell scripts       host1       host2       host3      # an inline comment is also possible
# you can also specify "aliases" - multiple names under which the host is also known       host4  myraspberrypi

As an afterthought and thanks to a suggestion of @Archemar:

User names are irrelevant on the IP level. At this level we deal only with hosts (or, rather, their interfaces), networks and similar entities. Users or their names never enter this picture at this level.

Using the above example hosts-file the following are all equal:

ssh [email protected]
ssh someuser@host4
ssh someuser@myraspberrypi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .