According to the error message, it looks like the config
files are missing on the Windows machine (e.g. this location C:/Users/{username}/.ssh/config
) or the read permission is missing.
Sometimes a problem arises when the SSH versions or the server-side and client-side versions of security algorithms mismatch.
But try following tests concerning Ubuntu server. In case all tests are OK,the problem is on Windows side.
Is the SSH daemon service running?
sudo systemctl status sshd.service
You must see a green dot at the left edge and status message Active: active (running)
.
Is the SSH daemon service listening on the TCP port 22?
sudo netstat -lntp | grep 22
In case the netstat
command is not installed, install it:
sudo apt-get update
sudo apt-get install net-tools
Right netstat answer shoud be like this:
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTENING 1702/sshd: /usr/sbi
tcp6 0 0 :::22 :::* LISTENING 1702/sshd: /usr/sbi
Is there a rule on the firewall allowing access to port 22?
sudo iptables-save | grep "\--dport 22"
or second possibility how to find the TCP 22 port rule with less strict filter:
sudo iptables-save | grep "22"
Right command response example is:
-A ufw-user-input -p tcp -m tcp --dport 22 -j ACCEPT
Local SSH selftest on the Ubuntu server
Preparation: Get/verify Ubuntu server own ip address by command ip addr
. Let the detected address be 192.168.1.50.
ssh -l your_username 127.0.0.1
and then
ssh -l your_username 192.168.1.50
You should connect your account back to the same server.
The w
command shows 1 extra line for each SSH connection to the same server.
w
Verify connectivity to Ubuntu server from another PC
Use another network node to check the situation from outside. Replace the 192.168.1.50
by real address of your server.
ping 192.168.1.50
Verify that port 22 on the Ubuntu server is visible as open from the outside.
telnet 192.168.1.50 22
Right output should be like this:
Trying 192.168.1.50...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
You can use other commands instead of the telnet to see via network the port 22 is opened. Responses are included below.
The netcat nc:
nc -4zv 192.168.1.50 22
Response:
Connection to 192.168.1.50 22 port [tcp/ssh] succeeded!
The nmap
sudo nmap -sT -p 22 192.168.1.50
Response:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-01-13 21:27 CET
Nmap scan report for localhost (192.168.1.50)
Host is up (0.000067s latency).
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.02 seconds
EDIT
Response to BulletproofCoffy comment
As for SSH keys, I assume you know what you're doing. Server keys must always be present and set correctly, otherwise neither remote nor local SSH connections will work.
From all your description, it looks like a problem of the local firewall on the server, unless there is another one between the two computers. For example, it is enough to have an incorrect rule order (a deny rule above an accept rule) or use the wrong profile (public/office/home) to render the rule allowing SSH is ineffective.
There is an easy test to verify whether the SSH traffic is blocked by a local firewall on the server or not. Turn off the firewall for a while.
sudo ufw disable
Then test from the other computer using the nc
to see if the availability of the SSH port has changed.
EDIT 2
I'm not sure I understood the situation correctly. Even directly on the server it is not possible to detect a port as open using the nmap
and nc
. At the same time, the netstat
command shows that the port is active and listening. Is that right?
I recommend this procedure:
Find out which application is listening on the SSH port using netstat. The last column of the statement contains the process number. Search for number in line valid for your SSH TCP port.
sudo netstat -lntp
Use the process number detected in the previous listing (e.g. 5678) to determine which application it belongs to.
ps -ef | grep 5678
Example of output:
root 1167 1 0 09:33 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
Find out if it's really your SSH daemon listening on your SSH port. Verify that the SSH port number has disappeared from the list of open ports when you stop the SSH daemon service.
sudo systemctl status sshd.service
sudo systemctl stop sshd.service
sudo systemctl status sshd.service
sudo netstat -lntp
Now test using another application directly on Ubuntu server (e.g. nc
) that the port intended for SSH can be opened and that it is visible over the network from another computer. Netcat start listening on the TCP port 22 in my example in Ubuntu first terminal window.
nc -k -l 22 > /dev/null
!!! Remember the nc
listener must be started either with -k parameter or again after each test !!!
Open second terminal on the same Ubuntu server and check if the port is opened:
sudo nestat -lntp
nc -4zv localhost 22
Test the port remotely from another network node. Use some commands described above (telnet
, nmap
, nc
).
If the port is now seen as open locally and remotely over the network, there is probably only one explanation, the faulty is the SSH daemon. Reinstall the SSH daemon.
Edit 3
The tests I designed were to help determine if the problem was with the SSH daemon application or elsewhere. The key is the answer to the question: Is the SSH TCP port visible from another computer as open when there is a different listening application than the SSH daemon in place of the daemon? If the answer is no, it means that the port is blocked somewhere and it has nothing to do with the SSH daemon. You need to figure out what is blocking the connection to the SSH port. Please try to repeat the test with the nc listening application on another completely free and not yet used port.
nc -k -l 777 > /dev/null
Turn off the UFW and try several times in a row to see if the port is visible as open locally and then from other devices on the LAN. Please use more than one device to test the port from the LAN, another PC or a smartphone with the Net Analyzer application is offered next.
If the port is available (open) from the LAN, stop listening the nc
and use the proven port number for the SSH daemon. Uncomment the #Port 22
line in the file /etc/ssh/sshd_config
, enter the new port number instead of 22, and restart the sshd service.
Verify with the netstat
and nc
that the new SSH port is open for both internal and external access.