10

I am new to linux and I am trying to establish a SSH connection with my friend's PC in the same LAN, but I am getting:

ssh: connect to host 192.168.71.70  port 22: Connection refused

Both ways are getting "connection refused." How can I fix this?

Eliah Kagan
  • 117,780
samanth
  • 101
  • 1
    Could you please verify, and then update the question, the following a) that your friend has the openssh-server installed and running, b) that it is listening on the default port 22 and c) that you have gotten the right ip address. – andol Feb 16 '12 at 07:09
  • and d)that a firewall is not blocking the connection – RobotHumans Feb 16 '12 at 07:16
  • Thank you for your response andol the problem is with the ssh-server was not installed. Now I have done it and it is working properly. – samanth Feb 16 '12 at 09:33

2 Answers2

14

Whether on a LAN or not on a LAN, I normally do this:

  1. First install openssh-server on all PCs that will be receiving the SSH connection:

    sudo apt-get install openssh-server
    
  2. Verify that the PC where I just installed openssh-server is accessible. The fastest way is to send it a ping.

ping 192.168.0.100 assuming the IP address is the IP address of my friend's PC. If it appears ok then I proceed with accessing to it. Remember that you need to use an account that already exists on your friend's PC. Normally his own account will do.

ssh friend@192.168.0.100 where friend is your friend's user name.

In a normal scenario this should be enough. Let me know if it works.

Luis Alvarado
  • 211,503
  • I would say part of this answer is correct which happens to be 'install openssh-server' but the verification part has nothing to do with SSH. The best way to make sure that the ssh server is working is to: 1. Make sure its turned on (sudo service ssh status) 2. On the client computer, telnet to port 22 on the box with ssh server (telnet server1.example.com 22) or nmap the ssh server (nmap server1.example.com). Pinging only tells the client that you can get to them via ICMP but you can still SSH into a server and disable ICMP on the kernel level... Just my two cents. – ruffEdgz Feb 16 '12 at 16:56
  • I have had friends installing SSH and spent an hour trying to connect to each other just to find out that they do not have any cables connected or do not have the network correctly setup to see each other. PING will just help with this and not think that SSH has the problem. Saves time. – Luis Alvarado Feb 16 '12 at 16:59
  • That's fine to add it to make sure for connectivity but you can do that PLUS make sure the ports are open by using nmap (sudo apt-get install nmap) from the client machine to the server machine as long as iptables isn't blocking all ports to the ssh server. I could be a bit picky on this but I want to make sure the correct checking is being done to verify that the service is actually on instead of just checking that a box is up and running. – ruffEdgz Feb 16 '12 at 17:07
  • Well by default I have seen that it is enough installing the openssh server. The ports are opened by default. You would have to block them or have a device block the port. So if the OP did this it would be something additional specific to him/her. Apart from this, yes doing a check with nmap or any other network tools is a good idea in multiple cases. – Luis Alvarado Feb 16 '12 at 17:12
5

When you try and connect, use the -vvv switch to show debug information:

ssh -vvv username@host
Goddard
  • 4,724
  • 2
  • 33
  • 51