Why does SSH not consult /etc/hosts?

I’m administrating a networked environment where the users authenticate over NIS.
All machines can be used to SSH into the server but one.
On the machine in question, I get the message


ssh: connect to host servername port 22: Connection refused

I compared strace outputs from the machine in question and a machine that can SSH into the server correctly.
It turns out the machine that can’t SSH into the server doesn’t consult /etc/hosts while the machine that can SSH correctly does. Both machines have /etc/hosts set up with the server’s name and IP. In the end, the machine that doesn’t consult /etc/hosts ends up trying to connect to 127.0.0.1 (localhost) and fails with the above message. What can be causing this?

Additional information:

  • The server I’m trying to SSH into also acts as the name server and both machines consult it while trying to SSH into it.
  • The machine that can’t SSH into the server can SSH correctly into other machines when I do

    ssh machinename

    The strace logs show that the machine consults the nameserver (this time successfully) and manages to resolve the remote machine name correctly and connect to it.

EDIT: I will gladly provide any additional information that you think might help solve this issue.

Asked By: Joseph R.

||

It sounds to me like the problem host does not have a correctly configured nsswitch.conf.

The hosts line of /etc/nsswitch.conf should look something like this:

hosts:  files nisplus nis dns

However, the exact contents will vary due to your environment. You should compare against working hosts and make changes accordingly.

Answered By: bahamat
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.