OpenSSH won't work 99% of the time!!

kanshira

macrumors member
Original poster
Oct 27, 2007
34
0
hi all, i've been browsing around the internet for a solution for a while but couldn't find a updated solution, so i'm finally starting up a thread for a solution.


I've been trying to OpenSSH to connect to my iphone folders for a while now but it won't work most of the time - I have gotten in a few times but after I logout and try again.. it won't go back in! ... so i know i've been doing something right. - i've tried both transmit and cyberduck(mac user) and they both fail to connect - i prefer using cyberduck.

i've tried doing ssh root@192.168.1.4 in terminal but end up with this msg:
ssh_exchange_identification: Connection closed by remote host

also, I have deleted known_hosts in the folder and that still didn't work

i'm using iphone 3gs 3.1.2 and presumably with the latest version of openssh.
 

dhlizard

macrumors G4
Mar 16, 2009
10,213
118
The Jailbreak Community
hi all, i've been browsing around the internet for a solution for a while but couldn't find a updated solution, so i'm finally starting up a thread for a solution.


I've been trying to OpenSSH to connect to my iphone folders for a while now but it won't work most of the time - I have gotten in a few times but after I logout and try again.. it won't go back in! ... so i know i've been doing something right. - i've tried both transmit and cyberduck(mac user) and they both fail to connect - i prefer using cyberduck.

i've tried doing ssh root@192.168.1.4 in terminal but end up with this msg:
ssh_exchange_identification: Connection closed by remote host

also, I have deleted known_hosts in the folder and that still didn't work

i'm using iphone 3gs 3.1.2 and presumably with the latest version of openssh.
Also, your IP address can change from day to day. Make sure the one you are using is still correct.
 

tag

macrumors 6502a
Apr 29, 2005
918
9
That error message could be referring to a large number of things. Try using the verbose x3 mode to see if any errors come up or if more info can be gathered about why the connection is getting closed when you connect.

Code:
ssh -vvv root@ipaddress
If that doesn't show the problem, I suppose you could always turn on system logging (via cydia app or manually) and then restart the ssh daemon or reboot the phone to see if any error messages come up in the syslog.
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
Same Problem here

Hi,
I'm facing the same problem here.

I did the verbose ssh thingy and got the following:

Code:
ssh -vvv root@192.168.1.8
OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.8 [192.168.1.8] port 22.
debug1: Connection established.
debug1: identity file /home/ali/.ssh/identity type -1
debug1: identity file /home/ali/.ssh/id_rsa type -1
debug1: identity file /home/ali/.ssh/id_dsa type -1
ssh_exchange_identification: Connection closed by remote host
my iPhone 3G (3.0 firmware) was not locked at all. I'm using openssh latest version.

I've searched all around the net but couldn't find any solution.

Any ideas?

Thank you
 

yezza

macrumors regular
Mar 12, 2008
225
0
Exactly the same thing here too :confused:




Hi,
I'm facing the same problem here.

I did the verbose ssh thingy and got the following:

Code:
ssh -vvv root@192.168.1.8
OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.8 [192.168.1.8] port 22.
debug1: Connection established.
debug1: identity file /home/ali/.ssh/identity type -1
debug1: identity file /home/ali/.ssh/id_rsa type -1
debug1: identity file /home/ali/.ssh/id_dsa type -1
ssh_exchange_identification: Connection closed by remote host
my iPhone 3G (3.0 firmware) was not locked at all. I'm using openssh latest version.

I've searched all around the net but couldn't find any solution.

Any ideas?

Thank you
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
That's weird

It's so weird that so many people have this problem but no solution for it yet. :(
 

Bl0ckHe1d

macrumors 6502
Nov 19, 2009
355
32
Caledonia
tried switching on "SSH" via sbssettings?? also check that the autolock is set to "Never" to prevent the iphone from going into "sleep" mode!
 

KidPub

macrumors member
Dec 8, 2009
89
15
Near Boston MA
localhost?

Are you able to ssh into localhost from the iPhone terminal app? If you can, it would point to something outside the phone as the issue (firewall etc).

Code:
 ssh localhost [\code]
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
It's in the phone

Hi,

Thank you KidPub for your reply.

I just tried (ssh localhost) on the terminal in the phone itself and I got the same error message:

ssh_exchange_identification: Connection closed by remote host


I already tried removing openssh and installing it again from cydia but that didn't fix it.

I guess this indicates there is something wrong with the default configuration of openssh on the iphone?
 

yezza

macrumors regular
Mar 12, 2008
225
0
coolthing76, I can confirm the exact same outcome as you on "ssh localhost" within the phones terminal - ie:

ssh_exchange_identification: Connection closed by remote host
 

NathanA

macrumors 6502a
Feb 9, 2008
739
16
I would try uninstalling OpenSSH one more time (and then reboot, NOT respring, afterward), but after it is removed, use something like iPhoneBrowser to see if there is an /private/etc/ssh directory. If there is, delete EVERYTHING in it as well as the directory itself. After that, reinstall OpenSSH and try one more time to make a connection.

The first time you attempt to make a connection after doing this, it may take longer than normal as it will need to generate a new set of RSA keys from scratch for itself again. Subsequent connections should be fast.

Also, I have noticed something on my 3GS (which I'm pretty sure was not the case on my 3G, but I'll have to double-check): if I connect the phone up to the network via WiFi, even after it gets an IP address, the phone is not immediately accessible after that. I will not be able to ping the IP address of the phone or make any sort of connection to the phone from outside UNTIL I have asked the phone to make an outbound connection (for example, open up Safari and go to a website). Not sure why this is. But it's possible that you are running into the same issue, which would explain your "99%" comment: it works occasionally because you tried to do it immediately after you were using the iPhone to access some other network resource.

-- Nathan
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
Answers

yezza

I think we both have exactly the same problem. Let's follow up on this thread until we find a solution with eh help of our great fiends here.
===========================

KidPub

Code:
ps -eal | grep ssh
gives:
Code:
-sh: ps: command not found
========================
foob

Here is my /etc/hosts file:

Code:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
=========================
NathanA

I will try your method when I go back home.



Thank you all for your help
 

meagain

macrumors 68030
Nov 18, 2006
2,563
23
I can't ssh into the phone for anything (via Cyberduck).
Some sort of peer disconnect.

I really need to save my cydia stuff before upgrading/jailbreaking.
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
Didn't work

NathanA

I tried what u said exactly. After I uninstalled Openssh I found the /private/etc/ssh directory full of files so I deleted it and its files, rebooted then reinstalled Openssh again.

I tried to ssh once more and it took some time before giving me the same error message.

I tried to use Safari a little and then download something form AppStore, then tried to reconnect again with ssh but still got the same ugly message:

Code:
ssh_exchange_identification: Connection closed by remote host
Note: I can ping my phone all the time, and I already disabled the auto-lock not to interfere with my ssh connections.

I know it seems really mysterious but I think there are many ppl with the same problem.

Thank you so much
 

NathanA

macrumors 6502a
Feb 9, 2008
739
16
Fascinating. By your description (took a long time the first time to give you the error), it does sound like sshd is probably running...it took longer the first time because it was regenerating your keys.

To get the 'ps' command on your phone that you tried to run earlier (as suggested by KidPub), you need to install "adv-cmds" package from Cydia. Then the command will work.

-- Nathan
 

yezza

macrumors regular
Mar 12, 2008
225
0
NathanA - I did as you suggested and have successfully connected via ssh :D

coolthing - it's unfortunate that this has not worked for you. Are you positive that the etc/ssh folder was deleted? FYI I used iPhone Explorer on my Mac to browse to the ssh folder to delete (after I had uninstalled openssh then rebooted).

I'm hoping that this fixes it permanently. I had re-installed openssh some time ago, and I was able to connect for a very short while, but then this ability mysteriously disappeared.
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
Output of ps

Hi NathanA,

I installed adv-cmds then did the (ps -eal | grep ssh) and got the following:

Code:
501  571  557  4002  0  31  0264728  180 -  R+  e03e3000 ttys000 0:00.01 grep ssh
=========================
yezza

Thanx for your concern. I'm glad ur problem is solved. Yes I'm sure I deleted the /etc/ssh folder and its contents but it didn't solve it for me. I used iFile on iPhone.
 

foob

macrumors 6502
Feb 17, 2009
306
0
sshd doesnt run in the background like it does on normal computers. It only launches when there is an incoming connection attempt. ps wont show anything until then.
 

coolthing76

macrumors newbie
Jan 30, 2010
9
0
Thank you

foob

Thank you for this depressing info lol

So is there another way to troubleshoot this problem?
 

yezza

macrumors regular
Mar 12, 2008
225
0
=========================
yezza

Thanx for your concern. I'm glad ur problem is solved. Yes I'm sure I deleted the /etc/ssh folder and its contents but it didn't solve it for me. I used iFile on iPhone.
Hey coolthing,

Unfortunately I'm back where I started. OpenSSH works when I re-installed it, but shortly afterwards it is again dysfunctional!

I just ran a short test:

1. Tried connecting via SSH - no go (connection closed by remote host).

2. Re-installed openSSH. Did not reboot.

3. Successfully connected via SSH.

4. Did an iTunes sync.

5. Successfully reconnected via SSH.

6. Rebooted phone.

7. Unsuccessful attempt to connect via SSH (connection closed by remote host).


Coolthing, can you reproduce the results of my test above?

Any ideas anyone? I have no idea what could happen over the course of a reboot. Perhaps something is over-writing part of the openSSH install/configuration?:confused: