connect to host localhost port 22: connection refused 

I ran into this problem when I tried to configure Hadoop in pseudo-distributed mode:

Problem:

$ ssh localhost
ssh: connect to host localhost port 22: Connection refused.

$ bin/hadoop fs -put foo input
Bad connection to FS. command aborted. exception: Call to localhost/127.0.0.1:9000 failed on connection exception: java.net.ConnectionException: Connection refused

Solution:
One possible reason is that because the ssh server daemon, or sshd, is not loaded and running on localhost, so any attempt to ssh connect to localhost would fail. I check to see whether ssh and sshd are running by typing the following command:

$ ps aux | grep ssh
# Result: bunch of lines, but none of them is about "sshd", only one line is about "ssh"

Result is, I only see ssh running, but not sshd. So I know ssh server daemon is probably not started yet.

First, I verify that I have installed the package “openssh-server” on my fedora box.

Then I check the status of sshd service:

$ systemctl status sshd.service
Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled) # sshd is disabled
Active: inactive (dead) # sshd is inactive

Here we go, it says the sshd service is currently disabled.

So I do the following commands to enable and start it:

$ systemctl enable sshd.service
$ systemctl start sshd.service

Now it is running!

If I check the status of sshd service again:

$ systemctl status sshd.service
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled) # sshd is loaded
Active: active (running) # sshd is active

Connecting ssh to localhost also woks fine now.