SSH connection getting refused
Solution 1
Whether on a LAN or not on a LAN, I normally do this:
First install openssh-server on all PCs that will be receiving the SSH connection:
sudo apt-get install openssh-server
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 [email protected]
where friend
is your friend's user name.
In a normal scenario this should be enough. Let me know if it works.
Solution 2
When you try and connect, use the -vvv
switch to show debug information:
ssh -vvv username@host
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
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?
-
ruffEdgz over 12 yearsI 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.
-
Luis Alvarado over 12 yearsI 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.
-
ruffEdgz over 12 yearsThat'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.
-
Luis Alvarado over 12 yearsWell 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.