0

I'm trying to connect to a remote linux server using a public key (it's not my server). I was given the public key and verified that I can connect just fine using WinSCP from a PC. However, the real goal is to automate and script the connection from a RHEL 7.5 box. Every time I try to connect from Linux, I immediately get "Connection Refused".

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 67: Applying options for *
debug2: resolving "ftp.server.org" port 333
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to ftp.server.org [x.x.x.x] port 333.
debug1: connect to address x.x.x.x port 333: Connection refused
ssh: connect to host ftp.server.org port 333: Connection refused
Couldn't read packet: Connection reset by peer

I get the same error if I try via SSH. ssh -i /data1/security/sftp/xxxx.key -p 333 -vv user@ftp.server.org

The only difference that I know of, is that when using WinSCP, it converts the public key file from an OpenSSL format to putty format.

Any ideas what is missing? I've never encountered this before.

6
  • One possibility: time zone differences. Linux usually defaults to UTC, Windows to the local time zone. SFTP requires synchronizing clocks (so encryption cannot be recorded and reused), so try changing time and time zone in Linux. – DrMoishe Pippik Jun 23 '20 at 20:12
  • Time zones or a problem with your public key wouldn't cause a "connection refused" error. The linux box is trying to connect to a different address or port than what winscp is connecting to, or else something like a firewall is interfering. – Kenster Jun 23 '20 at 21:55
  • Thank you; those are both good suggestions. The port listening is 333, so I'm told. And that is the port that works in WinSCP. My gut says it's something with the key file, or maybe the version of OpenSSL on my Linux box vs the target host, but I'm not sure. "Connection refused" is such an unhelpful error, I'm not sure which way to go. – Rupert Jun 24 '20 at 1:06
  • "Connection refused" means that a raw TCP connection cannot be opened. No key is involved at that point. OpenSSH version hardly matters either. Double check that the hostname and port is correct (consider posting WinSCP log file). Check that the hostname resolves to the same IP on both machines. If all matches, it is most probably a firewall issue. – Martin Prikryl Jun 24 '20 at 6:09
  • The WinSCP log was a good thought. But the IP and port and everything match. I tried using IP on Linux and get the same issue. I wonder if it could be that the target is not in the known_hosts file? I tried executing ssh-keyscan -vv -p 333 -H ftp.server.org >> .ssh/known_hosts but it doesn't add anything to the known_hosts file. – Rupert Jun 24 '20 at 12:28
1

When you read this :

debug1: connect to address x.x.x.x port 333: Connection refused
ssh: connect to host ftp.server.org port 333: Connection refused

That means you can not establish the TCP connection .

So that can be the firewall , or no daemon is listening on the server side , or you DNS resolution give you the wrong IP or unlikely from your location port 333 is filtered

1
  • After consulting with a network tech on our side, he told me that desktops and servers have different firewall rules. He opened port 333 for me and it connected on the first try. – Rupert Jun 29 '20 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.