LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ssh:connect to host restart port 22: Connection refused (https://www.linuxquestions.org/questions/linux-software-2/ssh-connect-to-host-restart-port-22-connection-refused-790293/)

myubuntu 02-19-2010 10:09 PM

ssh:connect to host restart port 22: Connection refused
 
Hi guys I am getting "ssh:connect to host restart port 22: Connection refused" error when trying to start "ssh" in Ubuntu. I uncommented the port 22 in ssh_config, I dont have iptables setup...Did try to check if the port is listening using the netstat -an | grep "LISTEN" & couldnt find. Any solutions pls......

VIJNB

win32sux 02-19-2010 10:12 PM

Quote:

Originally Posted by myubuntu (Post 3870001)
Hi guys I am getting "ssh:connect to host restart port 22: Connection refused" error when trying to start "ssh" in Ubuntu. I uncommented the port 22 in ssh_config, I dont have iptables setup...Did try to check if the port is listening using the netstat -an | grep "LISTEN" & couldnt find. Any solutions pls......

It sounds like the SSH daemon is listening on another port. Check the sshd_config file on the remote box and see what port it's configured to listen on, then use netstat to verify it's doing so.

BTW, this thread will likely be moved to a more appropriate forum, as it's not a security issue (at least not directly).

myubuntu 02-19-2010 10:15 PM

ssh:connect to host restart port 22: Connection refused
 
Hey thanks for your reply, checked the sshd_config, its also in port 22, any other solution

win32sux 02-19-2010 10:17 PM

Do you have some other means of accessing the remote box? The objective being to make sure it's actually listening on that port, and that there are no interfering firewall rules. If the remote box sits behind a dedicated firewall, you'll want to check that too.

myubuntu 02-19-2010 10:21 PM

No I dont have a remote box as I am trying this in stand alone Ubuntu & I did install the openssh-server, I am first trying to start the server.

win32sux 02-19-2010 10:26 PM

Quote:

Originally Posted by myubuntu (Post 3870011)
No I dont have a remote box as I am trying this in stand alone Ubuntu & I did install the openssh-server, I am first trying to start the server.

Uh, ssh_config isn't the server configuration file (it's the client configuration file). What you're looking for instead is sshd_config. Also, right after installation it should have generated the key pair and started itself up. If you need to manually start it, the command would be:
Code:

sudo /etc/init.d/ssh start
If you just execute the ssh command directly, you're running the client, not the server.

myubuntu 02-19-2010 10:32 PM

Yes I got the server started message, but when I tried to stop / start manually, it gave me the message, any clue??, I used the same code : sudo /etc/init.d/ssh start ....still getting the same error!!!!!

win32sux 02-19-2010 10:38 PM

Quote:

Originally Posted by myubuntu (Post 3870018)
Yes I got the server started message, but when I tried to stop / start manually, it gave me the message, any clue??, I used the same code : sudo /etc/init.d/ssh start ....still getting the same error!!!!!

Something's not adding up here. The connection refused error message you posted looks like an SSH client error, not a server one. The server doesn't try to start a connection. What's the output of:
Code:

sudo netstat -pantu | grep LISTEN

myubuntu 02-19-2010 10:42 PM

the output is

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 936/cupsd
tcp6 0 0 ::1:631 :::* LISTEN 936/cupsd
udp 0 0 0.0.0.0:68 0.0.0.0:* 979/dhclient
udp 0 0 0.0.0.0:5353 0.0.0.0:* 789/avahi-daemon: r
udp 0 0 0.0.0.0:47477 0.0.0.0:* 789/avahi-daemon: r

win32sux 02-19-2010 10:45 PM

What about the output of:
Code:

sudo /etc/init.d/ssh restart

myubuntu 02-19-2010 10:48 PM

Quote:

Originally Posted by win32sux (Post 3870028)
What about the output of:
Code:

sudo /etc/init.d/ssh restart

the same error - ssh:connect to host restart port 22: Connection refused

win32sux 02-19-2010 10:51 PM

Quote:

Originally Posted by myubuntu (Post 3870029)
the same error - ssh:connect to host restart port 22: Connection refused

Weird, it's like the SSH daemon's startup script is acting like a client.

What about:
Code:

ls -l /etc/init.d/ssh
And:
Code:

head /etc/init.d/ssh

myubuntu 02-19-2010 10:56 PM

Quote:

Originally Posted by win32sux (Post 3870032)
Weird, it's like the SSH daemon's startup script is acting like a client.

What about:
Code:

ls -l /etc/init.d/ssh
And:
Code:

head /etc/init.d/ssh

>> the output is.....

root@mgroms:~# ls -l /etc/init.d/ssh
-rwxr-xr-x 1 root root 3878 2009-10-22 15:50 /etc/init.d/ssh
root@mgroms:~# head /etc/init.d/ssh
#! /bin/sh

### BEGIN INIT INFO
# Provides: sshd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: OpenBSD Secure Shell server
### END INIT INFO

win32sux 02-19-2010 11:00 PM

That looks sane. I'm not sure what to make of this. Since this is such an early stage, would you be willing to re-install the SSH daemon package? It would go like:
Code:

sudo apt-get remove --purge openssh-server
sudo apt-get install openssh-server

Like I said, after that last command it should be up and running without the need for you to edit anything.

win32sux 02-19-2010 11:18 PM

FWIW, this is what the installation looks like on my Ubuntu 8.10 box:
Code:

win32sux@candystore:~$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree     
Reading state information... Done
Suggested packages:
  rssh molly-guard openssh-blacklist openssh-blacklist-extra
The following NEW packages will be installed:
  openssh-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 285kB of archives.
After this operation, 782kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com intrepid/main openssh-server 1:5.1p1-3ubuntu1 [285kB]
Fetched 285kB in 2s (114kB/s)         
Preconfiguring packages ...
Selecting previously deselected package openssh-server.
(Reading database ... 213706 files and directories currently installed.)
Unpacking openssh-server (from .../openssh-server_1%3a5.1p1-3ubuntu1_i386.deb) ...
Processing triggers for ufw ...
Processing triggers for man-db ...
Setting up openssh-server (1:5.1p1-3ubuntu1) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
 * Restarting OpenBSD Secure Shell server sshd                                                                                                        [ OK ]

win32sux@candystore:~$ sudo netstat -pantu | grep LISTEN | grep ssh
tcp        0      0 0.0.0.0:22              0.0.0.0:*              LISTEN      19719/sshd     
win32sux@candystore:~$ sudo /etc/init.d/ssh restart
 * Restarting OpenBSD Secure Shell server sshd                                                                                                        [ OK ]
win32sux@candystore:~$



All times are GMT -5. The time now is 09:06 AM.