On my work, technology and related stuff....

Posts Tagged ‘ssh’

4 comments

If you are developing for/on a jailbroken iPhone or iPad you are more than likely going to have to SSH into your iDevice a number of times. This includes transferring files to/from the device via SCP. Entering a password every time you have to SSH into the device is very tedious.  Moreover, this becomes imperative if you need automation scripts to SSH/SCP into the device
 
This post explains how you can enable public-key authentication with SSH in order to bypass the password entry process. Note that enabling password-less entry into your iDevice is a potential security risk because anyone with access to your system can now access/control your device without any authentication. So if you enable this, be sure to secure access to your systems!

The steps to enable public-key authentication with the iPhone/iPad are no different than with any UNIX system.
 
The following commands need to be executed on the system from which you would be SSHing into your iPhone/iPad.
If you are using a Mac or a Linux system, the commands are executed from the terminal window.  If you are using a Windows PC, you would have to run these commands within Cygwin

  • Go to the .ssh folder

MyMacBook-Pro-2:~.mactester$ cd ~/.ssh

  • Generate public/private key-pair by running the ssh-keygen command. You will be prompted for some information. You can leave the file to save the key as default. Enter a passphrase . You will be prompted for the passphrase when you try to access your key.

MyMacBook-Pro-2:.ssh mactester$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/Users/mactester/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mactester/.ssh/id_dsa.
Your public key has been saved in /Users/mactester/.ssh/id_dsa.pub.

  • A public/private key pair would have been generated in the .ssh folder. The .pub file corresponds to the public key.

MyMacBook-Pro-2:.ssh mactester$ ls
id_dsa             id_dsa.pub

  • Copy the PUBLIC KEY over to the ~/.ssh folder of your iPhone/iPad (in this example, the IPAddress of my device is 192.168.1.10)

MyMacBook-Pro-2:.ssh mactester$ scp id_dsa.pub root@192.168.1.10:~/.ssh

The following commands need to be executed on your iPhone/iPad.
For this, you can SSH into the iDevice  (You would still be prompted for a password at this stage) or  you can type in the following commands directly in the terminal application window of your jailbroken iDevice

  • Save the public key as “authorized_keys”. If you already have public keys associated with other systems stored on your device, be sure to append the public key to “authorized_keys2” as shown in the example below. Make sure you set the right access permissions on the key.

MyiPhone:~root# cd ~/.ssh
MyiPhone:~/.ssh root# cat id_dsa.pub >> authorized_keys2
MyiPhone:~/.ssh root#chmod 0600 authorized_keys2

That’s it. The next time you SSH into your iDevice, you will not be prompted for a password.
 

32 comments

Earlier this week, I jailbroke my iPhone4 iOS4.3.5 device. The jailbreak solution that is currently available for iOS4.3.5 is tethered jailbreak. If you are not familiar with “Tethered Jailbreak”, it essentially means that rebooting the jailbroken device would require it to be connected /tethered to the PC/MAC. This is of course not ideal but under the circumstances, this was my only option (And no-I couldn’t downgrade to iOS 4.3.3 for various reasons which are not directly relevant to this post).
 

Installing the jailbreak Software

I used Redsn0w V0.9.8b3 jailbreak tool. Follow the instructions provided here. The process is very straightforward.
 

Cydia Crashing Issue

Although the jailbreak completed successfully, the Cydia icon was white and it crashed as soon as I clicked on it. To get around it, I rebooted the device by running Redsn0w in tethered mode. Be sure to check the “Just boot tethered right now” option on Redsn0w . Once the device rebooted, the Cydia app started working. No more crashes. I was able to download and install apps.  Unfortunately, some of them required a reboot and I had to go through the tethered reboot process again
The  MobileTerminal, OpenSSH and Aptupdate for SBSettings were among the packages that I installed. These packages will come in handy as you will see below.
 

Installing third party apps directly

Next, I wanted to install a third party app directly to the phone. The third party app was not available through Cydia sources or the AppStore.
For this, I copied the .app file corresponding to my app into the /Applications folder on the iPhone , created the /var/mobile/Documents folder and updated the file permissions by running the commands listed below from a terminal window on my MAC. Ofcourse,  I substituted "IPhoneIPAddress" with the IPAddress of my jailbroken phone while executing the commands

Note: Creation of the Documents folder is required only the first time (unless you delete it between installations)
I rebooted the device in tethered mode. When the device rebooted, the app was ready. I could launch it and run it.
So far, so good until..

I tried to launch Cydia app, it crashed. All the other apps on the phone worked as normal.
 

Cydia Crashing Issue..Again.

So I rebooted the phone again in tethered mode.  This time the reboot had no effect. The other option was to re-jailbreak but I did not want to do that just yet.
Instead, I uninstalled and re-install the Cydia app by running the following commands from the terminal window of my MAC.  I substituted "IPhoneIPAddress" with the IPAddress of my jailbroken phone while executing the commands
 

 
Note: The AptUpdate for SBSettings that I installed earlier automatically installed the apt tools .
Once I did that, cydia was back up and running again. I currently have version 1.1.1 of Cydia on the phone. Everything else continues to work as expected.
Now, its appears that installing the third party app caused Cydia to crash but it is unclear to me why that was the case because Cydia started working again after re-installation and the third party app continues to work as well. In any case, now I know what I should do to resolve the problem should it resurface but its less than ideal.
 

In Conclusion..

With the number of reboots that I had to do, the tethering is especially tedious. If you are considering jailbreaking your iOS device, I would recommend that you refrain from updating it to 3.4.5. for now and wait for an untethered release of jailbreaking software if possible.