PDA

View Full Version : OpenSSH won't work 99% of the time!!




kanshira
Dec 4, 2009, 10:02 PM
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.



thelatinist
Dec 4, 2009, 10:37 PM
i'm using iphone 3gs 3.1.2 and presumably with the latest version of openssh.

You should probably remove and then reinstall openssh just to be sure.

dhlizard
Dec 5, 2009, 06:57 AM
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
Dec 5, 2009, 05:43 PM
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.

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.

Drewsky87
Dec 5, 2009, 11:21 PM
You're not letting your phone goto sleep are you?

coolthing76
Jan 30, 2010, 01:12 PM
Hi,
I'm facing the same problem here.

I did the verbose ssh thingy and got the following:

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
Jan 30, 2010, 03:01 PM
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:

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
Feb 1, 2010, 11:39 PM
It's so weird that so many people have this problem but no solution for it yet. :(

Bl0ckHe1d
Feb 2, 2010, 01:37 AM
tried switching on "SSH" via sbssettings?? also check that the autolock is set to "Never" to prevent the iphone from going into "sleep" mode!

coolthing76
Feb 2, 2010, 05:08 AM
Hi,

Thank you Bl0ckHe1d for your reply.

I tried all these but no go

KidPub
Feb 2, 2010, 10:49 AM
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
Feb 2, 2010, 11:37 AM
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
Feb 2, 2010, 05:19 PM
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

KidPub
Feb 2, 2010, 10:06 PM
How many sshd processes are running?

ps -eal | grep ssh

Perry

foob
Feb 2, 2010, 10:42 PM
And what does your /etc/hosts file look like?

NathanA
Feb 3, 2010, 01:29 AM
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
Feb 3, 2010, 03:35 AM
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

ps -eal | grep ssh

gives:

-sh: ps: command not found

========================
foob

Here is my /etc/hosts file:

##
# 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
Feb 3, 2010, 01:23 PM
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
Feb 3, 2010, 02:04 PM
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:

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
Feb 4, 2010, 12:48 AM
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
Feb 4, 2010, 04:49 AM
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
Feb 5, 2010, 04:52 AM
Hi NathanA,

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

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
Feb 5, 2010, 10:55 AM
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
Feb 6, 2010, 03:43 AM
foob

Thank you for this depressing info lol

So is there another way to troubleshoot this problem?

yezza
Feb 6, 2010, 04:33 PM
=========================
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:

coolthing76
Feb 8, 2010, 12:59 PM
yezza

Same thing here.


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. (Skipped) Did an iTunes sync.

5. (Skipped)Successfully reconnected via SSH.

6. Rebooted phone.

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


Anyways, my goal is to do this:
http://aikhan.wordpress.com/2009/06/01/developing-iphone-applications-on-linux/

I can live with reinstalling OpenSSH every time i reboot my iPhone which I rarely do :)

This took some time already any ideas from anyone is welcome for sure.

Thank you everyone

mappyman
Feb 8, 2010, 04:40 PM
Delete the ".ssh" directory if you have one in roots home directory.

drwxr-xr-x 2 root sys 68 Sep 26 07:04 empty

Also does the above directory have the same permission as mine, its located in /var

foob
Feb 8, 2010, 07:07 PM
Can you ssh in as mobile instead of root? Can you ssh from the phone to the pc using MobileTerminal?

MrThompsonR
Feb 8, 2010, 08:08 PM
Also, your IP address can change from day to day. Make sure the one you are using is still correct.

Depending on your router/ DHCP settings your ip address will change every few minutes... Just verify the "current" assigned ip address before trying to connect to your phone... and make sure you turn off the "auto lock."

yezza
Feb 9, 2010, 03:46 AM
Can you ssh in as mobile instead of root? Can you ssh from the phone to the pc using MobileTerminal?

ssh from mobile terminal gives me "connection refused".

ssh mobile@192.168.... gives me the same result as root:

"connection closed by remote host"

sanctifi3d
Mar 10, 2010, 01:23 PM
I have the very same problem I've been trying to fix it for ovewr a week now cant seem to get it to work :( any suggestions? I restored a couple of times and none fixed it

NCUSA
Mar 10, 2010, 02:17 PM
Why don't you try with USB way to connect your iPhone..

I'm using iFunBox and it works great, it's like WinSCp so you don't need to worry..
Here is the video that's going to help you: http://www.youtube.com/watch?v=mNBZ-D8uEBM

baoshi
Apr 16, 2010, 10:46 PM
Hi Guys,
I found this thread when I'm googling the same problem.
My observation is that each time I cannot ssh to iPhone, the reason is /usb/sbin/sshd gets deleted
FYI I'm running OS 3.1.2 and iTunes 9.1

yezza
Apr 17, 2010, 06:27 AM
Hi Guys,
I found this thread when I'm googling the same problem.
My observation is that each time I cannot ssh to iPhone, the reason is /usb/sbin/sshd gets deleted
FYI I'm running OS 3.1.2 and iTunes 9.1

Hello baoshi,

Yes you're right (good spotting), I have the same thing happening.

I am on 3.1.2 and iTunes 9.1 also, but I have had this problem whilst on iTunes 9.0 too. I'm still hoping for a solution.

bbhepa
May 4, 2010, 01:32 PM
I have the exactly same problem here, and have been trying to solve it for over a week now.

I guess baoshi found the source of our headache.

Messages such as "ssh_exchange_identification: Connection closed by remote host" is very very misleading; the "ssh_exchange_identification" only tells us where the ssh client was executing when "Connection closed by remote host" happened. The connection close is an asynchronous event and it is not related to "ssh_exchange_identification" in any logical way.

What's happening here is that the server side (the iphone) accepts and establish a connection from the ssh client by means of the inetd process, and the inetd simply shutting down the connection because the actual server program, the sshd, that should serve this connection does not exist.

In addition to the /usr/sbin/sshd, I noticed /usr/libexec/sshd-keygen-wrapper is spontaneously removed also.

The next problem is

"Who the heck is removing these files, and why?"

bbhepa
May 5, 2010, 10:04 AM
Folks, the problem is solved, at least those caused by spontaneously disappearing /usr/sbin/sshd. It is done by the worm type malware called "ikee" or something like it.

Google it in the web, or refer to pages like:

http://forums.justcommodores.com.au/lan-lounge/118975-iphone-ikee-worm-fix.html

In my case, I usually change password asap, but it seems like it hit me within the split second time rag.

My personal thoughts about this incident is that the openssh package should be installed as disabled, then enabled at users command.

Good luck to those having the same problem.

yezza
May 6, 2010, 05:12 AM
Folks, the problem is solved, at least those caused by spontaneously disappearing /usr/sbin/sshd. It is done by the worm type malware called "ikee" or something like it.

Google it in the web, or refer to pages like:

http://forums.justcommodores.com.au/lan-lounge/118975-iphone-ikee-worm-fix.html

In my case, I usually change password asap, but it seems like it hit me within the split second time rag.

My personal thoughts about this incident is that the openssh package should be installed as disabled, then enabled at users command.

Good luck to those having the same problem.

Thanks bbhepa, that seems to have fixed my problem :D

I was under the impression that my wallpaper would change to Rick Astley if I had the worm (and my wallpaper had not changed), but gave the removal process a whirl anyway.
:D

rocteur
Nov 20, 2010, 04:09 AM
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.

... Deleted ...

-- Nathan

This worked for me! Thanks Nathan but I also had to follow these instructions:

http://forums.justcommodores.com.au/...-worm-fix.html

/usr/sbin/sshd disappeared

yink
May 29, 2011, 11:53 AM
Hi all, I spent the whole day trying to figure this out. After reinstalling openssh, I would be able to ssh into my own phone by running
ssh localhost

However, after a while, ssh localhost would fail and I would get the dreaded
ssh_exchange_identification: Connection closed by remote host

Turns out that my iPhone is infected with the ikee worm as you guys pointed out. Not too sure how that happened especially cos I did a fresh iOS 4.3.3 install the day before (at home) and changed my default passwords soon after. I also checked Pwnage Tool's SHA-1 to ensure I used a legit version to bake the custom ipsw file for my iPhone.

My family has 3 other iOS devices. The 3 other devices have all been jailbroken at some point but they are not currently jailbroken. Doing fresh OS installs and not jailbreaking subsequently probably means they don't have the worm right? I don't think I got infected from my home network.

I think the biggest suspect is installing stuff from Cydia, which I did a ton of after jailbreaking. Let me check up on this and see if I can come up with anything.

Also, thanks for all the tips!

beej69
May 30, 2011, 12:47 AM
yikes!

my first encounter with iPhone malware :( that's what i get for installing openssh before changing the default "alpine" password for users mobile and root :( i'm so glad i stumbled across this thread!

IMNSHO, the most important thing is to nuke /System/Library/LaunchDaemons/com.ikey.bbot.plist

an easy way to do this is to use iPhone Explorer from http://www.macroplant.com/iphoneexplorer/

if you don't see this file, you're suffering from some other problem. nuking the other files mentioned here and elsewhere is just cleanup. the above file is the one that makes the malware load every time your iphone boots.

if you're feeling paranoid, restore and be careful to change your default passwords before installing openssh next time :)

good luck!
marc