ssh: connect to host myremotehost.com port 22: Connection refused
Solution 1
Your ISP may block connections to port 22 (nothing you or your router can do about it). Just set SSHd to run on a different port, e.g. 2222.
In /etc/ssh/sshd_config
, change Port 22
to Port 2222
and then sudo service ssh restart
. Port forward 2222 (or whatever), and try again.
Solution 2
Just to share. (might be with different configuration)
In my case, I found that that error can happen because I have not install openssh-server
in the other machine.
After I install openssh-server in the other machine, the problem:
ssh: connect to host 192.168.XXX.XXX port 22: Connection refused
is solved.
Solution 3
First check
openssh-server
installed in that system.check the status of ssh service, make ssh service start.
sudo service ssh status sudo service ssh start
Check whether port 22 in that system is blocked by
iptables
. Just allow port iniptables
and then check.sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
Else change port number of
ssh
from 22 to 2222 by editingvi /etc/ssh/sshd_config /etc/init.d/ssh restart.
Solution 4
I solved this problem by reinstalling openssh-server as follows:
sudo apt-get purge openssh-server
sudo apt-get install openssh-server
Solution 5
Check the SSH service status and start the SSH service if it is stopped:
sudo service ssh status
In my case SSH was stopped, but after starting the service:
sudo service ssh start
I can be able to remote login to Linux.
IMMORTAL
Updated on September 18, 2022Comments
-
IMMORTAL about 1 year
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <AppXmlLogWritter> <LogData> <LogID>5678201301211226306349434819061642515658</LogID> <LogDateTime>**20130121**122630</LogDateTime> <LogType>Warning</LogType> <LogFlag>PMLogFlag</LogFlag> <LogApplication>PMLogApplication</LogApplication> <LogModule>PMLogModule</LogModule> <LogLocation>PMLogLocation</LogLocation> <LogText>PMLogText</LogText> </LogData> <LogData> <LogID>5678201301211226306349434819063542617610</LogID> <LogDateTime>**20130121**122630</LogDateTime> <LogType>Warning</LogType> <LogFlag>PMLogFlag</LogFlag> <LogApplication>PMLogApplication</LogApplication> <LogModule>PMLogModule</LogModule> <LogLocation>PMLogLocation</LogLocation> <LogText>PMLogText</LogText> </LogData> <LogData> <LogID>5678201301211226306349434819065542731198</LogID> <LogDateTime>**20130121**122630</LogDateTime> <LogType>Warning</LogType> <LogFlag>PMLogFlag</LogFlag> <LogApplication>PMLogApplication</LogApplication> <LogModule>PMLogModule</LogModule> <LogLocation>PMLogLocation</LogLocation> <LogText>PMLogText</LogText> </LogData> <LogData> <LogID>5678201301211226306349434819067442849561</LogID> <LogDateTime>**20130117**122630</LogDateTime> <LogType>Warning</LogType> <LogFlag>PMLogFlag</LogFlag> <LogApplication>PMLogApplication</LogApplication> <LogModule>PMLogModule</LogModule> <LogLocation>PMLogLocation</LogLocation> <LogText>PMLogText</LogText> </LogData> </AppXmlLogWritter>
From the above XmL file i want to read the xml document in between the range. such I implement the windows form with datetimepicker control for From Date and To Date and one submit button when i choose date from FROM DATE and also from the TO DATE it display the date into list view from these from tow different date for this i have write the code as
private void btnSubmit_Click(object sender, EventArgs e) { XmlElement objXmlRoot = objXmldoc.DocumentElement; if (chkBoxFromDate.Checked && chkBoxToDate.Checked) { strXpathQuery = "/AppXmlLogWritter/LogData[LogDateTime >='" + dateTimePickerFromDate.Value.ToString("yyyyMMdd") + "' and LogDateTime <='" + dateTimePickerToDate.Value.ToString("yyyyMMdd") + "']"; } }
I use this query to display data but it shows me blank data.
-
I4V almost 11 yearsIs this homework? stackoverflow.com/questions/14435803/…
-
-
bahudso over 11 yearsI still get the same connection refused error (22 when I don't specify a port when using ssh and 2222 when I use -p 222). I put incoming port 22 to forward to 2222 and changed the port to 2222 in sshd_config. Am I leaving out something?
-
ish over 11 yearsJust try this: Incoming 2222 on router has to forward to 2222 (with port 2222 set in
sshd_config
). -
belacqua over 10 yearsThis does not seem like a 'likely cause', especially given the accepted answer.
-
GTodorov almost 6 years@izx kudos for the router rules. At some point I thought that I was freaking out and don't know what I'm doing. LOL!
-
Shashanth about 5 yearsFor future readers. Make sure that you are referring
/etc/ssh/sshd_config
(notice sshd) file. After pulling my hair for an hour I came to know this small difference. ;P -
tudor -Reinstate Monica- about 5 yearsMy new router uses port 22 for it's remote administration feature and doesn't list it anywhere on the interface, so it may not necessarily be the ISP.
-
user227495 over 3 yearsOn client or server ? Sorry, I don't know much.
-
Ahwar about 3 yearsI am using Google Cloud Shell and no matter what I try the error is the same.
-
Qazi Fahim Farhan about 3 yearsThanks! It worked for me! This should be the accepted solution!
-
soheil zabihi over 2 yearsOn client......
-
Admin over 1 yearin my case ssh was failing while starting the service. This error was the output:
sshd: no hostkeys available -- exiting
and this was the fix:ssh-keygen -A