Search:  
Gentoo Wiki

IPhone

Contents

About

The iPhone from Apple is a device capable of playing music with a good audio quality and a good mobile phone. In this guide you'll learn how to connect it to Amarok using OpenSSH on the phone and to manage the audio collection of the device.

Warning: Firstly, this guide assumes that you already have a jailbroken iPhone, if you don't know anything about this, check Google.
Warning: Secondly, as of the date of this edit there is currently *NO* way to sync an iPhone with 2.0+ firmware from Linux. Apple, like Microsoft, embraces the lets-put-locks-in-our-software strategy. In a nutshell, the iPhone's hashing scheme for writing files readable by the device's media player was successfully reverse engineered with firmware version 1.1.4. Subsequently, Apple changed their hashing scheme making it more cryptic with the release of firmware version 2.0+, and to date this hashing scheme has not been reverse engineered. WHAT THIS MEANS TO YOU: If you want to sync movies from Linux to your iPhone, you need to go through an elaborate process of downgrading your firmware from 2.0 to 1.1.4. After that, everything will be dandy. You'll be able to wirelessly sync your movies and music through open-source software such as gtkpod and Amarok. All will be well. First, however, you'll need to pull your hair out following esoteric instructions on downgrading and jailbreaking your phone. Check Google for that. Have a nice day!

Connection

You should connect the iPhone at a wireless network so that you can access it's IP from the remote PC, I.E. To the same router of your Computer. Then on the iphone, go to:

Code:
Settings -> Wi-Fi -> YourNetwork ->

And read the IP address of the iphone, i.e. 192.168.1.100

Now, on the PC:

ssh root@192.168.1.100

It will prompt for a password, enter alpine and hit enter.

Note: alpine is the standard password for the iphones 1.1.3 or 1.1.4, while in 1.1.1 or 1.1.2 it should be dottie

Changing the root password

Ok, now you're in the iPhone. First of all you should change the root password, cause it's a bit unsafe now. You shouldn't use passwd cause it's buggy, so we're going to generate the password on the PC and write it manually in the iphone.

perl -e 'print crypt("yourpassword", "/s");'

This will return something like /sM0V04hwjBp2 , you should copy it and paste in the /etc/master.passwd file of the iphone, removing the old one for root and mobile.

nano /etc/master.passwd
Note: Protip: download vim through one of the package managers (Cydia/Installer) and use that instead :P
Note: Update: it seems password setting through passwd is no longer dangerous as of firmware 1.1.4

Passwordless login

Now your iPhone is safe, but you can't enter the password anytime you link it to Amarok, so we should setup a passwordless login for your PC. this is done with RSA authentication.

First of all you have to enable RSA Authentication on the iphone, so in the iphone go and edit /etc/sshd_config.

nano /etc/sshd_config

Uncomment the following lines:

Code:
 RSAAuthentication yes
 PubkeyAuthentication yes
 AuthorizedKeysFile .ssh/authorized_keys

Save and exit.

Note: This file has also been found at /etc/ssh/sshd_config.

Now you need an rsa key pair, on the PC you can generate it using ssh-keygen, remember to not assign a password to it, or it will be useless, also you have to do this with the user that will use Amarok.

Code:
ssh-keygen
 Generating public/private rsa key pair.
 Enter file in which to save the key (/home/user/.ssh/id_rsa): {hit enter}
 Enter passphrase (empty for no passphrase): {hit enter}
 Enter same passphrase again: {hit enter}
 Your identification has been saved in /home/user/.ssh/id_rsa.
 Your public key has been saved in /home/user/.ssh/id_rsa.pub.
 The key fingerprint is:
 e6:90:cc:41:ae:f0:98:3e:5d:66:1a:33:d0:21:72:08 user@localhost

The next step, is to copy it on the iPhone, this is easily done (Remember to set the right ip for your iphone):

ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.100

Now enter your password and you should be done. Try to connect to the iphone using ssh, if it doesn't ask a password you can skip to the next paragraph, else you probably have ste's openssh, and you have to do some more steps on the iphone:

Code:
cd ~
mv .ssh/authorized_keys .ssh/authorized_keys2
chmod 755 /var/root
chmod 700 /var/root/.ssh
chmod 644 /var/root/.ssh/authorized_keys

Reboot the iPhone and it should work. if it doesn't go to the troubleshooting section.

Check for the iTunes directory

The iPhone can save the Media directory (With the itunes library) in /var/root or in /var/mobile, you should check now where it's and take note.

Note: One contributor's comment: in all my experience I've never seen the iPhone default to using root for the general UI. From my multiple experiences, the library, custom applications, settings, etc., have always belonged to user 'mobile'. Thus one should take note and review the past steps which advised setting up the ssh mount for read/write to the ipod under the root user. More likely than not, you'll end up breaking your file system with file-permission issues. Of course that's nothing that can't be fixed with a simple 'sudo chown -R mobile:mobile /', but my point stands. Please correct me if I'm wrong.

/var/root is used by the iPhone firmware 1.1.2 and below /var/mobile is used by the firmware 1.1.3 and above

FUSE and sshfs

Ok, now you have full access to the iPhone, but Amarok can't connect to it directly over SSH, it needs the iPhone to be mounted on the PC like a normal device. It's rather easy to do, using FUSE And sshfs which mounts a remote ssh device like a normal device.

Kernel

FUSE have to be compiled in the kernel (Or as a module autoloaded using modules.autoload.d), so you have to select it:

Linux Kernel Configuration: kernel configuration
File systems  --->
  <*> Filesystem in Userspace support

Install

Next, you have to emerge Fuse and sshfs:

emerge -av sys-fs/fuse sys-fs/sshfs-fuse}}

Mount

Now, we need to configure sshfs to be used by a normal user, so we need to set (as root) the right permissions to /usr/bin/fusermount.

chmod 4755 /usr/bin/fusermount

We need to make (As user) the mountpoint.

mkdir ~/iphone

Test

Finally, let's try to mount the iPhone. Remember to use the right Media directory previously individuated and the right iPhone IP!

sshfs mobile@192.168.1.100:/var/mobile/Media ~/iphone

Amarok

Recompile with iPod USE flag

That's easy, you just need to add the ipod use flag to /etc/make.conf or to emerge amarok using this command:

echo "media-sound/amarok ipod" >> /etc/portage/package.use
emerge media-sound/amarok

Setup the iPod link in the iPhone

(Note! The instructions in this paragraph are no longer relevant. You can safely leave this step out.) Amarok doesn't know the new iTunes directory present in the iPhone, so we need to link it to the old iPod_Control, remember to use the right Media path.

ln -s iTunes_Control iPod_Control

Select your GUI of choice for syncing your media library: gtkpod or Amarok

gtkpod

Emerge gtkpod:

   emerge gtkpod

Mount your iThing:

   sudo modprobe fuse; sshfs ~/iphone mobile@192.168.x.x:/var/mobile

Run gtkpod:

   host ~ $ gtkpod

Click things

   clickclickclickclick (the interface is pretty intuitive), just hit save once you're done and it'll begin the wireless sync

Amarok

Oo.et.oO 17:32, 5 September 2008 (UTC) note: amarok did NOT work correctly when trying to add songs to a previously songless iphone. the songs appeared in the seemingly correct itunes dirs:

 iTunes_Control/Music/F*

but the ipod app on the iphone couldn't see them. in addition when connected back to my windows itunes it reported that it could not read from the iphone at all and wanted me to restore all settings. i deleted the iTunes_Control directory and itunes could see the phone again. i'm going to try putting a few songs on the iphone from itunes first and see what happens. perhaps the iphone db is a bit different than standard ipods and i need to update libgpod? i'll check back later.

We're almost done, the amarok configuration is pretty simple. Open Amarok, Go to Settings, Configure Amarok, Devices and click to "Add a device..."

Select as a plugin "Apple iPod" As name, any name, like "iPhone" As a mount point, "/home/youruser/iphone"

Now save it and go to configure, setting this as a pre-connection command:

sshfs mobile@192.168.1.104:/var/mobile/Media /home/youruser/iphone

and this as post-disconnection command:

fusermount -u /home/youruser/iphone

Restart Amarok and you're done.

Troubleshooting

Asked for a password when using passwordless setup

# ls -al ~/.ssh
total 4
drwxr-xr-x 2 root wheel 102 Nov 21 04:25 .
drwxr-xr-x 6 root wheel 306 Nov 20 00:02 ..
-rw-r--r-- 1 root wheel 395 Nov 20 03:01 authorized_keys

sshfs returns "fusermount: mount failed: Operation not permitted"

Check if the /usr partition (The root partition if you doesn't have any /usr partition) is mounted with the "user" option in fstab, which implies "nosuid". Those options must be removed.

Retrieved from "http://www.gentoo-wiki.info/IPhone"

Last modified: Mon, 29 Sep 2008 10:46:00 +0000 Hits: 2,576