128

While installing hadoop in my local machine , i got following error

ssh -vvv localhost 
OpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011 
debug1: Reading configuration data /etc/ssh/ssh_config    
debug1: Applying options for * 
debug2: ssh_connect: needpriv 0 
debug1: Connecting to localhost [127.0.0.1] port 22. 
debug1: connect to address 127.0.0.1 port 22: Connection refused 
ssh: connect to host localhost port 22: Connection refused

can some one help me to resolve this error , than changing port number

guntbert
  • 536
  • 6
  • 19
Surya
  • 3,408
  • 5
  • 27
  • 35

31 Answers31

155

If install Hadoop on Mac OSX, make sure turn on Remote Login under System Preferences then File Sharing. This worked on my machine.

Remote Login

vladof81
  • 26,121
  • 9
  • 38
  • 41
118
  1. Remove SSH with the following command:

    sudo apt-get remove openssh-client openssh-server
    
  2. Install SSH again with:

    sudo apt-get install openssh-client openssh-server
    

It will solve your problem.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Divyang Shah
  • 1,578
  • 1
  • 11
  • 22
40

Do you have sshd installed? You can verify that with:

which ssh
which sshd

For detailed information you can visit this link.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Tariq
  • 34,076
  • 8
  • 57
  • 79
  • 2
    i tried giving sudo apt-get install openssh-server command , it started to ask password for hduser , where i didnt create any password for the user, how i can know the default password – Surya Jun 27 '13 at 06:48
  • i tired which ssh , which sshd , this gives me the internal path '/usr/bin/ssh' , they are already installed in my machine – Surya Jun 27 '13 at 07:00
  • 3
    ssh is the client and sshd is the server. To install `sshd` use `sudo apt-get install openssh-server`. When you created the user account for `hduser`, you must have created a password. Do not confuse that with the empty passphrase you might have set for passwordless ssh from the `hduser` account to itself on localhost. – arun Jan 18 '15 at 23:36
29

Try installing whole SSH package pack:

sudo apt-get install ssh

I had ssh command on my Ubuntu but got the error as you have. After full installation all was resolved.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Michael Z
  • 3,883
  • 10
  • 43
  • 57
  • 1
    This solved it for me, was exactly my situation (I also already had sshd installed and running, out of the box). On Ubuntu 19.04. – Jonathan Hartley Jun 06 '19 at 19:52
  • 1
    Worked in Ubuntu 20.04. Same situation. – arthropod Nov 04 '21 at 14:57
  • Thumbs up. Previously I installed `sudo apt-get install openssh-client` on Ubuntu 22.04 and it returned the error. Now with the full SSH package pack install, error gone. – bim Nov 07 '22 at 16:05
21

I use a Mac, this worked for me:

Open System Preferences, then search for 'sharing'.

Choose Remote Login, make sure it is on and remember to add required users.enter image description here

Got it from here

Dami
  • 677
  • 6
  • 12
20

I did all the suggestion above and it did not work. Then I restart the ssh service and it works. This is what I do:

service sshd restart

Then I redo

ssh localhost

Now I can connect to my localhost. Hope it helps

Arwan Khoiruddin
  • 436
  • 3
  • 13
13

Check if this port is open. Maybe your SSH demon is not running. See if sshd is running. If not, then start it.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
abhinav
  • 1,252
  • 10
  • 27
  • i tried giving sudo apt-get install openssh-server command , it started to ask password for hduser , where i didnt create any password for the user, how i can know the default password for hduser – Surya Jun 27 '13 at 06:48
  • 1
    No it is asking the password for root/ sudo user of linux system where you are installing. – abhinav Jun 27 '13 at 06:58
  • [root@localhost .ssh]# which ssh /usr/bin/ssh [root@localhost .ssh]# which sshd /usr/sbin/sshd , ssh is already installed in my machine – Surya Jun 27 '13 at 07:01
  • 1
    then run the sshd demon /bin/etc/init.d sshd start – abhinav Jun 27 '13 at 07:03
  • sshd re-exec requires execution with an absolute path , this is message from the path – Surya Jun 27 '13 at 07:11
  • any support how to make this up – Surya Jun 27 '13 at 09:25
13

I used:

sudo service ssh start

Then:

ssh localhost
Linh
  • 163
  • 2
  • 8
8

If you restart service then it will work

$ service sshd restart

then check

$ ssh localhost

It will work

Boiethios
  • 38,438
  • 19
  • 134
  • 183
Rushikesh
  • 81
  • 1
  • 1
7

Make sure that /etc/hosts.allow contains:

ssh:ALL:allow
sshd:ALL:allow

OR

ssh:localhost:allow
sshd:localhost:allow

OR - some other variant

ssh:{host1,host2,host3...}:allow
sshd{host1,host2,host3...}:allow

INSURE that the first line in the file DOES NOT begin with ALL:ALL:DENY

NOTHING will be able to communicate with the host... on any port.

j0k
  • 22,600
  • 28
  • 79
  • 90
Larry Helms
  • 71
  • 1
  • 2
4

For my case(ubuntu 14.04, fresh installed), I just run the following command and it works!

sudo apt-get install ssh

Shiqing Fan
  • 688
  • 2
  • 8
  • 14
4

For what its worth I got the following error trying to ssh into my local machine, running Ubuntu 16.04 Xenial, from a vm.

 ssh: connect to host 192.168.144.18 port 22: Connection refused

It got immediately fixed with:

sudo apt-get install ssh

Take note, Before fix: 'which sshd' returned nothing and 'which ssh' returned

/usr/bin/ssh

And After the fix: 'which sshd' returned

/usr/sbin/sshd
IskandarG
  • 323
  • 1
  • 3
  • 9
3

It might be caused by some of the following:

  1. SSH Server is not installed (only SSH Client), try: apt-get install ssh openssh-client openssh-server
  2. Connection is blocked by iptables (Firewall), try: ufw allow ssh
damian1baran
  • 1,307
  • 1
  • 14
  • 13
3

On mac go to system settings->network->sharing and allow remote login.

try ssh localhost

You should be good.

3

What worked for me is:

sudo mkdir /var/run/sshd
sudo apt-get install --reinstall openssh-server

I tried all the above mentioned solutions but somehow this directory /var/run/sshd was still missing for me. I have Ubuntu 16.04.4 LTS. Hope my answer helps if someone has the same issue.

Frida Schenker
  • 1,219
  • 1
  • 9
  • 14
3
  1. Before installing/reinstalling anything check the status of sshd . . .
sudo systemctl status sshd
  1. You should see something like . . .
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor prese>
   Active: inactive (dead)
     Docs: man:sshd(8)
           man:sshd_config(5)
  1. Just enable and start sshd
sudo systemctl enable sshd
sudo systemctl start sshd
0p3r4t0r
  • 623
  • 5
  • 13
2

Actually i solved this, I just installed shh daemon.

in terminal :

sudo apt-get install openssh-server

User Learning
  • 3,165
  • 5
  • 30
  • 51
2

If you're certain that you have installed ssh, then it's possible that ssh and/or sshd has been terminated or the server service hasn't been started. To check whether these processes are running use:

//this tells you whether your ssh instance is active/inactive
sudo service ssh status

OR

//this list all running processes whose names contain the string "ssh"
sudo ps -A | grep ssh

It's likely that ssh would be active and running but sshd would not. To enable them:

sudo service ssh start

NB; - some systems have a restart option but mine didn't

2

try sudo vi /etc/ssh/sshd_config

in first few lies you'll find

Package generated configuration file

See the sshd_config(5) manpage for details

What ports, IPs and protocols we listen for

Port xxxxx

change Port xxxxx to "Port 22" and exit vi by saving changes.

restart ssh sudo service ssh restart

1

My port number is different. i tried using

ssh localhost -p 8088

this worked for me

j0k
  • 22,600
  • 28
  • 79
  • 90
Surya
  • 3,408
  • 5
  • 27
  • 35
1

If you still face problems, try the following:

sudo ufw enable    
sudo apt-get install openssh-server

This might work too.

OhBeWise
  • 5,350
  • 3
  • 32
  • 60
Dinesh
  • 11
  • 1
1

A way to do is to go to terminal

$ sudo gedit /etc/hosts

***enter your ip address ipaddress of your pc  localhost 
    ipaddress of your pc  localhost(Edit your pc name with localhost) **

and again restart your ssh service using:

$ service ssh restart

Problem will be resolve. Thanks

1

if you are using centOS or Red Hat, you should first update SElinux. Execute the following statement

ausearch -c 'sshd' --raw | audit2allow -M my-sshd

then you need to execute

semodule -i my-sshd.pp

good luck

0

You may should edit your /etc/hosts. For example if my hostname is ub0, but the hostname in /etc/hosts is localhost, it may occur

connect to host ub0 port 22: Connection refused

Because the hostname in /etc/hosts is localhost not ub0.

So, you should be careful the hostname when building up distributed clusters.

GoingMyWay
  • 16,802
  • 32
  • 96
  • 149
0

For Linux:

  1. Remove SSH with the following command:

    sudo apt-get remove openssh-client openssh-server
    
  2. Install SSH again with:

    sudo apt-get install openssh-client openssh-server
    
finefoot
  • 9,914
  • 7
  • 59
  • 102
0

you need to check the configuration in sshd_config ListenAddress 0.0.0.0 update this and restart the sshd service that will resolve the issue.

Rupeshrams
  • 31
  • 1
0

if you are able to ping and not able to ssh, then it is a firewall. The firewall on 18.4 (not sure about other versions) in on by default and only allow port 8080.

Here how you fix it

https://linuxconfig.org/how-to-enable-disable-firewall-on-ubuntu-18-04-bionic-beaver-linux

agabsi
  • 1
0

Check file /etc/ssh/sshd_config for Port number. Make sure it is 22.

hiruna72
  • 26
  • 2
0

What worked for me was modifying the ssh config file to the following:

Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa

0

On WSL supported ubuntu I ran

service ssh start

Then

ssh localhost

It worked

Eric Atinga
  • 31
  • 1
  • 3
-1

if youre apache server is not running your local host wont run check that out there are some articles if you dont get it i will leave a link here ;)

check this

I had same error got it done rn

peqhv2
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30439479) – Emi OB Nov 29 '21 at 13:08