How To: Stream Music From The iPhone In Ubuntu

This is the first how-to article that holds your hand step by step to stream music from the iPhone in Ubuntu over Wi-Fi. This will work on other distributions, simply replace apt-get with your package manager of choice.

Requirements:

– 1.02 Firmware iPhone with OpenSSH installed via Installer.app
– Ubuntu, or probably any distribution based on apt-get (such as Debian)
– Wireless Router (ad-hoc connection probably works too, untested)

These instructions were performed on brand new Ubuntu 32-bit installation of Gutsy Gibbon (7.10). They have been found to be complete and accurate. Installing OpenSSH on the iPhone is outlined in other articles available online, simply search for “iPhone jailbreak” and follow instructions, you will need a Windows PC or Mac.

Using two programs called FUSE (Filesystem in Userspace) and sshfs we can mount the iPhone filesystem in Linux, then configure ssh key pairs so we can connect without needing to sudo or login as root every time we want to sync the phone, then we’ll install beta versions of Libgpod and Rythmbox to end up with something insanely great:

screenshot-tokyo-ska-paradise-orchestra-loverswalk.png

1. Installing FUSE and other needed programs.

On your PC, goto Applications, Accessories, Terminal
Search for gstreamer in add/remove programs and add everything with the name starting with gstreamer, including ubuntu restricted extras.

Note: You can copy-paste every command from this article using CTRL+Shift+V.

sudo apt-get install sshfs

Then, add yourself to the fuse group with this command:

sudo adduser wayne fuse [Replace wayne with your username]

Re-authenticate using su - wayne to avoid /dev/fuse errors later on (or reboot). We’ll be leaving this terminal open for the rest of this guide.

2. Setting up Hosts file, Configuring OpenSSH password, and Configuring SSH Key Pairs
This lets you connect to your iPhone without using a password every time.

Turn off auto-lock on your iPhone by going to Settings | General | Auto-Lock | Never

Adding the iPhone to /etc/hosts
Open a terminal, type:

sudo gedit /etc/hosts

Edit the file to look like this, changing 10.0.0.196 to the IP address of your iPhone:

iPhone Host File Setup

You can find the IP address of your iPhone by either by looking in your wireless router configuration page (now would be an excellent time to make it a static DHCP address) or on the phone by going to Settings | Wi-Fi, then tapping the blue arrow next to the access point.

Save and quit gedit, you’ll be back to the terminal.

In the terminal we’ll generate SSH keys and connect to the iPhone

ssh-keygen -t rsa

Should output something like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/wayne/.ssh/id_rsa): [ENTER]
Enter passphrase (empty for no passphrase): [ENTER]
Enter same passphrase again: [ENTER]
Your identification has been saved in /home/wayne/.ssh/id_rsa.
Your public key has been saved in /home/wayne/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx [email protected]
[email protected]:~/Desktop$

4. Logging into the iPhone via SSH, Resetting Passwords, and setting up the iPhone SSH Keys.
ssh [email protected]

Don’t worry, if it takes a long time – the first time you connect, it takes about 30 seconds to generate keys on the iPhone.

[email protected]:~/Desktop$ ssh [email protected]
The authenticity of host 'iphone (10.0.0.196)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'iphone,10.0.0.196' (RSA) to the list of known hosts.

[email protected]'s password: dottie [This is the default password]
#

At the # prompt type the following:
passwd root [Type in the new password twice.]
passwd mobile [Type in the new password twice.]

Configure SSH keys on the iPhone.

mkdir ~/.ssh << [Error that it exists is OK.]
chmod go-w / ~
cp /etc/ssh_config /etc/ssh_config.bak
echo AuthorizedKeysFile .ssh/authorized_keys >> /etc/sshd_config
exit

You should see the following output:
Connection to iphone closed.
[email protected]:~$

5. Configure SSH keys on your Linux PC/
scp ~/.ssh/id_rsa.pub [email protected]:.ssh/authorized_keys

You should see something like this:
[email protected]'s password: [type the new password you setup here]
id_rsa.pub 100% 393 0.4KB/s 00:00
[email protected]:~$

6. Mount your iPhone using sshfs

sudo mkdir /media/iphone/ -m 777

When running sshfs you may receive errors. Common ones are about /dev/fuse – logout, reauthenticate using su - wayne, or rebooting is a simple solution (although not needed).

sshfs [email protected]:/var/root/Media /media/iphone/
ln -s /media/iphone/iTunes_Control /media/iphone/iPod_Control

7. Install SVN versions of Rhythmbox and Libgpod

Download the debs here. (Thanks funk for packaging these!)
Extract this file with Archive Manager, then double click on each one and install each package.

After installing all of these, when you open up Rhythmbox via Applications | Sound & Video | Rythmbox, your iPhone will magically appear in the devices list, and allow you to stream media via wireless. If it’s not working, make sure that you can still browse to /media/iphone and view files yourself.

To ummount the iPhone:
fusermount -u /media/iphone

To re-mount the iPhone:
sshfs [email protected]:/var/root/Media /media/iphone/

Did you run into any problems? Comment here and I’ll help you out best I can.

Bonus tip: Mount /var/root/Library/Ringtones instead and load up on ringtones!