SSH times out when trying to connect - ssh

A few days ago i was rsyncing files to my server but it suddenly froze. Then i noticed that my SSH session also froze. When i tried sshing back it froze once again. Today my friend wanted me to ssh into his server so he made me a user gave it a password etc... (Note that he has succesfully ssh-ed in and sshd is running on port 22) but when i tried to connect it froze once again so i ran the command again with:
-vvv
The output is:
OpenSSH_9.1p1, OpenSSL 1.1.1q 5 Jul 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname <the ip address of the server> is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/anon/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/anon/.ssh/known_hosts2'
debug3: ssh_connect_direct: entering
debug1: Connecting to ip [ip] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: connect to address ip port 22: Connection timed out
ssh: connect to host ip port 22: Connection timed out
That is the info i was able to gather but here is some general system info:
Os: arch (freshly updated)
I haven't tried much apart from updating my system since i am not an expert at SSH.

Related

Gitlab ssh connection timeout (with Cloudflare and Client crt)

I can't connect to my gitlab server. The webUI is secured with Cludflare and Client cert. But that should not really matter because I want to connect with ssh
ssh -Tvvv git#gitlab.domain
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/userdir/.ssh/config
debug1: /home/userdir/.ssh/config line 1: Applying options for gitlab.domain
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/userdir/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/userdir/.ssh/known_hosts2'
debug2: resolving "gitlab.domain" port 12345
debug3: resolve_host: lookup gitlab.domain:12345
debug3: ssh_connect_direct: entering
debug1: Connecting to gitlab.domain [123.123.123.123] port 12345.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: connect to address 123.123.123.123 port 12345: Connection timed out
debug1: Connecting to gitlab.domain [123.123.123.123] port 12345.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
~/.ssh/config
Host gitlab.domain
HostName gitlab.domain
User gitlabuser
Port 12345
PreferredAuthentications publickey
IdentityFile ~/.ssh/git
(The key is stored in the corresponding account)
What could be the reason for this?
As long as a curl -v telnet://gitlab.domain:12345 shows you a timeout, that means:
either the network route is not opened between your machine and gitlab.domain:12345
or gitlab.domain does not listen on port 12345
Double-check your GitLab ssh port configuration and make sure it is up and running, using the port you need.

SSH Remote Port Forwarding Empty Response

I am trying to Remote port forward from Raspberry pi in my local network using ssh on my windows pc
ssh -R 5941:localhost:8000 pi#192.168.1.191
So from the above command, I am trying to forward connections from port 5941 on Raspberry pi server (192.168.1.191) to port 8000 on my pc (localhost) which hosts a web server on port 8000
The above ssh command executes with no errors but when i try to access http://localhost:5941/ on Raspberry Pi (192.168.1.191) i get
ERR_EMPTY_RESPONSE
I have tried
Turned off firewall on my Windows PC
netstat on raspberrypi gives me
$ sudo netstat -a | grep 5941
tcp 0 0 0.0.0.0:5941 0.0.0.0:* LISTEN
tcp6 0 0 [::]:5941 [::]:* LISTEN
when i run the ssh command in verbose mode
ssh -R 5941:localhost:8000 pi#192.168.1.191 -v
I get this
debug1: Remote connections from LOCALHOST:5941 forwarded to local address localhost:8000
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions#openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: console supports the ansi parsing
debug1: client_input_global_request: rtype hostkeys-00#openssh.com want_reply 0
debug1: Remote: Forwarding listen address "localhost" overridden by server GatewayPorts
debug1: remote forward success for: listen 5941, connect localhost:8000
debug1: All remote forwarding requests processed
and when i try to access http://localhost:5941/ on Raspberry Pi (192.168.1.191) i get this on ssh console
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 3 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 5941, originator ::1 port 58122
debug1: getsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([::1]:8000) in progress, fd=7
debug1: channel 1: new [::1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connected to localhost port 8000
debug1: channel 1: free: ::1, nchannels 2
How should I further diagnose my problem ?
The solution to this is to put 127.0.0.1 instead of localhost
ssh -R 5941:127.0.0.1:8000 pi#192.168.1.191
This forces ipv4 instead of ipv6, for some reason ssh port forwarding in windows fails to work on ipv6, I was able to work the same command with localhost on linux just fine.
I found the solution from this post here

ssh - Control socket does not exist - Operation timed out

When I try to SSH on to my remote desktop from my Mac, I get this error message:
$ ssh -vvvv john#dev-dsk-john.com
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/john/.ssh/config
debug1: /Users/john/.ssh/config line 26: Applying options for *
debug1: /Users/john/.ssh/config line 40: Applying options for dev-dsk*.amazon.com
debug1: /Users/john/.ssh/config line 165: Applying options for *.us-east-*.amazon.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: auto-mux: Trying existing master
debug1: Control socket "/tmp/ssh_mux_dev-dsk-john.com_22_john" does not exist
debug2: resolving "dev-dsk-john.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to dev-dsk-john.com [10.1.133.160] port 22.
debug1: connect to address 10.1.1.1 port 22: Operation timed out
ssh: connect to host dev-dsk-john.com port 22: Operation timed out
The connection hangs at
debug1: Connecting to dev-dsk-john.com [10.1.133.160] port 22.
It was working three days ago.
The system says the host is still active, so I'm pretty sure the computer is still powered on.
I faced the same problem today, and finally managed to fixed it.
I first verified that the control socket really doesn't exist. My path was "/home/ethan/.ssh/controlmasters/ethan#a.b.c.d:22" and this didn't exist.
I then ran ssh like:
ssh -M -S /home/ethan/.ssh/controlmasters/ethan#<ipaddr>:22 server.example.org
Now, it connects and also creates the control socket. Subsequently, I could open another ssh and that didn't require password and things worked normally.

How to debug ssh tunnel that works and then hangs after an indeterminent time

I have two machines, m_remote and m_server. I can successfully set up an ssh tunnel from m_remote to m_server using:
ssh -f -N -T -R22222:localhost:22 m_remote_user_on_server#123.123.123.123 -i /path/to/.ssh/m_remote_key
Where 123.123.123.123 is the m_server IP address. And I can successfully use that tunnel from m_server to m_remote using:
ssh m_server_user_on_remote#localhost -p 22222 -i /path/to/.ssh/m_server_key
However after a period of time the tunnel becomes unresponsive and it's no longer possible to use it. I have to access the remote machine directly and restart the tunnel. Is there any way of debugging this? From the remote all I get is:
$ ssh -vvvv m_server_user_on_remote#localhost -p 22222 -i /home/server_user/.ssh/m_server_key
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /home/server_user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "localhost" port 22222
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22222.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /home/server_user/.ssh/m_server_key type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/server_user/.ssh/m_server_key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
Then after a long pause of at least 2 minutes it logs out:
ssh_exchange_identification: Connection closed by remote host
Though this is due to a cron job I've set up to periodically kill and restart the tunnel.
** Edit **
On OSX 10.11 it's the same debug log with an additional line:
...
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: permanently_drop_suid: 501 # <-- additional line before hanging
I'm not certain as I need to diagnose and correlate this but as the m_remote machine is on a flaky home wifi connection this may be dropping and causing the tunnel to hang.
Alternatively there may be some config option such as ControlPersist (which may only be relevant to master connections) which has a low default of perhaps 10 minutes which could be increased.

Cannot ssh from Mac OS X to Linux

I have Linaro running in an embedded system (Zedboard). I am using the Mac Terminal to ssh to this system. The Zedboard has an IP. I set it in the interfaces file. This board is not connected to the internet and it is not running any firewall. I cannot ssh to this machine.
$ ssh -vvv root#169.254.218.146
OpenSSH_5.6p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 169.254.218.146 [169.254.218.146] port 22.
debug1: connect to address 169.254.218.146 port 22: Connection refused
ssh: connect to host 169.254.218.146 port 22: Connection refused
Shouldn't there be a debug3 for the third verbose? Ping works however. I can ping just fine and it responds. Any help is appreciated. Thank you.
EDIT: I noticed some strange behavior. My very first connection (after booting up Linaro) actually times out.
root#Vinayak’s MacBook Pro ~ $ ssh -vvv root#169.254.218.146
OpenSSH_5.6p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 169.254.218.146 [169.254.218.146] port 22.
debug1: connect to address 169.254.218.146 port 22: Operation timed out
ssh: connect to host 169.254.218.146 port 22: Operation timed out
Any SUBSEQUENT ssh's give the connection refused result.
None of the information displayed by the third debug level is relevant here. It displays additional details about the SSH connection, but no connection is being established at all here, so there's nothing to say.
Your output indicates that the Zedboard is not running an SSH server, or it is not configured to accept connections on this IP.