0

I am trying to establish a ssh connection with another machine with a port which is already occupied by some other resource

The SSH is not getting timed out

> ssh -v -p 8080 10.10.10.10
OpenSSH_4.2p1, OpenSSL 0.9.8a 11 Oct 2005
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.10.10.10 [ 10.10.10.10 ]
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established
debug1: identify file /home/abc/.ssh/identity type -1
debug1: identify file /home/abc/.ssh/id_rsa type -1
debug1: identify file /home/abc/.ssh/id_dsa type 2
debug1: ssh_exchange_identification :
debug1: ssh_exchange_identification : \022\\[
debug1: ssh_exchange_identification : \022\\Z
debug1: ssh_exchange_identification : \022\\[
debug1: ssh_exchange_identification : \022\\Z
debug1: ssh_exchange_identification : \022\\[

Machine 10.10.10.10 is up and running properly . Port 8080 already occupied by some other resource . The above logs are not ending . Its not getting timed out.

I tried adding with the parameter ConnectTimeout , but no change in the behaviour .

I am expecting some message this

ssh -v -p 77 10.10.10.10

OpenSSH_4.2p1, OpenSSL 0.9.8a 11 Oct 2005
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.10.10.10 [ 10.10.10.10 ] port 77.
debug1: connect to address 10.10.10.10 port 77 : Connection refused
>

Why this behavior of SSH. Please help ..

  • *Why* are you doing this? Some of the time you have sshd listening on port 8080, and some of the time you have some other service listening on port 8080, correct? What do you hope to accomplish by this (that you can't accomplish by running sshd on one port and the other service on another port)? There has to be a better way of doing what you're trying to do. – dave4420 Jul 05 '12 at 07:52
  • The problem is "ssh -v -p 8080 10.10.10.10" hangs and there is no way to tell that the command has failed . – Preetham Shenoy Jul 05 '12 at 09:47
  • No, the problem is that you are using ssh to connect to a port that is running some other service. You should be doing something else instead. But until you tell us *why* you are doing this, we can't sensibly suggest *what* you should be doing instead. – dave4420 Jul 05 '12 at 10:33
  • The reason why I am doing like this because , 'In my application , this is a fail case scenario , where the user gives this port number as a parameter and expects a false message on the screen, instead my application is hanging which is not expected . ' – Preetham Shenoy Jul 05 '12 at 11:14
  • May be there is a security requirement where the port is chosen on a configured parameter. So I think we need to see if we can help the member. As far as I see, it is a valid question - but cannot think of any answer other than precheck if port is free before starting the operation. – kumar_m_kiran Jul 10 '12 at 12:44

1 Answers1

1

You get that Connection refused only, when there is no program listening on port 77. The program listening on that port is waiting for connections, but it can't understand what ssh is sending (i.e. the ssh protocol).

ott--
  • 5,642
  • 4
  • 24
  • 27
  • In the first example , the command hangs . Due to this my script hangs and doesnt continue. I wanted it to execute and return failure which is not happening . – Preetham Shenoy Jul 05 '12 at 09:55
  • Use `ssh -o ConnectTimeout=5 ...` to timeout after 5 seconds. – ott-- Jul 05 '12 at 10:16
  • As i mentioned earlier "I tried adding with the parameter ConnectTimeout , but same problem occurs " – Preetham Shenoy Jul 05 '12 at 11:08
  • @PreethamShenoy Try 2 different options for that case: `ssh -o ServerAliveInterval=3 -o ServerAliveCountMax=2 ...`. – ott-- Jul 05 '12 at 12:28