Synching iPhone over USB under Ubuntu

April 30th, 2009 by alex

iPhone is not very good under Linux. It is locked down by the Apple Corp, and they tell you what you can and can not do with it. The first step in getting Linux compatibility is, naturally, setting iPhone  free of all its predispositions. The process is trivial and well documented on the web (google “jailbreak”), but do not forget to back up your stuff first. If you do backup, iTunes will restore it after the iPhone has had its brains cleansed, but if you don’t backup, you will be just like me. Now, onto the fun stuff! Modding, tethering and getting all that multimedia loaded on.

One way to connect to the iPhone is through its WiFi interface. I played around with Ubuntu’s Ad-Hoc networking and I could say this – it sucks. Using both the NetworkManager and the WICD, I could get the WiFi created, connect the laptop and the iPhone to it, but I could not get either one to ping an other. Plus, iPhone’s battery was draining like a leaking toilet. So, I choose the USB route, the faster, simpler, more secure way that, coincidentally, keeps iPhone from discharging. The USB route is a less traveled one, but hopefully the following will help you navigate the obstacles.

  1. First, get all the prereqs:
    apt-get install build-essential cmake libglib2.0-dev libxml2-dev python-dev swig automake autoconf libtool libgnutls-dev libusb-dev libfuse-dev libglib2.0-dev libxml2-dev libreadline5-dev
  2. Then, install libplist (needed for libiphone)
    git clone git://github.com/JonathanBeck/libplist.git
    mkdir build
    cd build
    cmake ..
    make
    sudo make install
    sudo ln -s /usr/local/lib/libplist.so.0.0.12 /usr/lib
    sudo ln -s /usr/lib/libplist.so.0.0.12 /usr/lib/libplist.so.0
    sudo ln -s /usr/lib/libplist.so.0 /usr/lib/libplist.so

    You might need to use different version numbers (libplist.so.0.0.xx) if you get a latter version of libplist
  3. Now, install libiphone
    git clone git://github.com/MattColyer/libiphone.git
    ln -s plist-folder/ swig/plist
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ln -s /usr/local/lib/libiphone.so.0 /usr/lib/
  4. Get iTunnel and run it (your iPhone ssh should be turned on)
    ./itunnel 7777
  5. Now go and change the iTunes DB version to an un-encrypted one (this no longer works if you have iPhone OS 3.0 and higher)
    ssh -p 7777 root@localhost
    cp /System/Library/Lockdown/Checkpoint.xml
    /System/Library/Lockdown/Checkpoint.xml.bak
    nano /System/Library/Lockdown/Checkpoint.xml
    find (^W) and change DBVersion to 2.
  6. Terminate the tunnel and reboot the iPhone.
  7. Start the tunnel back up and mount the iPhone:
    sshfs -p 7777 root@localhost:/var/mobile/Media /media/iphone/ -o workaround=rename
  8. Setup Amarok
    1. Click Settings → Configure Amarok.
    2. Choose Media Devices.Hit Add Device. Select Apple iPod Media Device for the plugin type.
    3. Point it at your mount point /media/iphone
    4. In Devices, click Connect. Once connected, click on the double arrows on the right hand side of the Connect, Disconnect, and Transfer buttons. A list of options opens up, one of which is iPod. Choose iPod → Set iPod Model → Mobile Phones → iPhone
  9. Enjoy

Tethering:

  1. For tethering try this:
    ssh -D 9800 -p 7777 mobile@127.0.0.1
    -D sets a SOCKS proxy.
  2. If you use Opera as your browser of choice (I do, its the best! ) instruct it to use the SOCKS proxy on localhost:9800.
  3. If you are using Firefox, also set its DNS in about:config set
    network.proxy.socks_remote_dns=true.
    Or you could go int Edit > Preferences > Advanced > Network > Connection Settings

Yeah, I know, this only works with apps that can go through a proxy. The only other way I can think of is to set up an openvpn tunnel inside of the SSH tunnel. It might be worth trying, but iPhone OS 3.0 with native teethering shall be out soon, hopefully sparing all that effort. Again, may be not.

Gotchas:

  • Make sure you’ve got your FirewireGUID already setup (I.e. you’ve connected the iPhone to iTunes via USB after flushing its brain)
  • Unmount gphoto2 gvfs iPhone share when it is automounted
  • iTunnel does not support scp/sftp. According to the iTunnel author it supports scp, but sftp clearly did not work. SFTP works too.
  • If iTunnel fails with -5 try running it again.

References:

Tagged with: , , , .

21 Comments

  • cong says:

    Very nice tutorial! I had a bit of blunder with my directory structure at the beginning, but everything worked. I using it to sync an ipod touch.

    I can send music now, but I was wondering if you knew a way of sending photos and videos?

    • alex says:

      cong, Photos are easy – copy them from private/var/mobile/Media/DCIM/100APPLE/. If you need to upload, generate a tumbnail and name it the same, look in the DCIM folder for an example. Videos are a bit tricky – they are in private/var/mobile/Media/Videos but in encrypted and AFAIK people cannot upload them yet.

  • sto says:

    hello

    thanks for this tuto.
    unfortunately it does not work for me, i get strange errors :

    raissa@dell:~/itunnel-0.0.5$ ./itunnel 7777
    get_iPhone() success
    - successfully got device
    server waiting for ssh connection
    server accepted connection, clientfd:5
    client thread fd(5) running, server port 7777 , peer port 39207
    tunnel now running.
    SSH to localhost port 7777 to get to iPhone.
    (use ssh -D to create SOCKS tunnel.)
    do Ctrl+C to quit the server (can take a few seconds).
    client is still waiting for handshake.
    WOAH! client failed to get proper syn+ack.
    peer sent connection reset. setting error: -104
    client thread fd(5) encountered USB read error: -104
    client thread fd(5) reader ended.
    client thread fd(5) terminating

    no idea what to do, aas i am not an expert.

    ps : i had to change /usr/local/lib/libplist.so.0.0.11 to 0.0.12, seeems there is a new version out there…

    • alex says:

      sto, I am no expert either, but looking at iTunnel code (and using it) showed that the app is rather unpolished, more of an alpha/beta code state. May be the iTunnel guy could help?

    • tentotwo says:

      Hello there,

      I get exactly the same error message as you. Have you contacted Jing Su (the guy who created itunnel) with this problem yet?

      Regards
      Jake

      • tentotwo says:

        Fixed it! Embarrassing newbie mistake: SSH wasn’t installed on the iPod Touch. I thought it was there by default, but it wasn’t. Everything’s working great now!

  • just me says:

    is there a way through which I could ssh INTO ubuntu from my iphone over the usb cable?? I really need to. how do I do that? thank you!!!!

    • alex says:

      This is currently not possible. One would have to implement TCP/IP over USB module (like usbnet) for iPhone before SSH could be used on the phone over USB. It looks what what iTunnel is doing, is translating SSH traffic to Apple’s USB protocol that iPhone uses. If you do have it running on the host side and connected with SSH, then you can use the existing tunnel from the iPhone (specify RemoteForward in .ssh/config first). But if you need it initiate the SSH from iPhone, your best bet is to use iPhone’s wi-fi, not USB.

  • just me says:

    root@sesebuntu:~/Desktop/itunnel/build# cmake ..
    CMake Error: The source directory “/root/Desktop/itunnel” does not appear to contain CMakeLists.txt.
    Specify –help for usage, or press the help button on the CMake GUI.

    should I create that file on my own? or is the install process suppoosed to create that?

    root@sesebuntu:~/Desktop/itunnel/build# sudo make install
    make: *** No rule to make target `install’. Stop.
    root@sesebuntu:~/Desktop/itunnel/build#

    what does this mean?

    • alex says:

      itunnel comes with the binary. Try simply running it – worked fine for me under ubuntu (assuming you’ve got your libiphone compiled as described above)

  • just me says:

    Im sorry, I wasnt paying enough attention to point out that that sudo make install error comes up at step 3, precisely the one with libiphone. any ideas? ubuntu 9.04 all updated

  • Alex A. says:

    I have gotten pretty far in your tutorial so far but running the ./itunnel 7777 gives me an error that clearly has to do with me not properly compiling libiphone

    What I did was compile libplist in ./build i then copied and pasted all the downloaded files from libiphone into ./build then ran everything until the make command which leaves me with:

    make: *** No targets specified and no makefile found. Stop.

    So I then cannot finish compiling it in the ./build folder

    And when I do get this to work do I then drop all the downloaded files from itunnel into that folder?

    P.s. as much as I can get around on Ubuntu I only installed it two weeks ago so sry in advance if this is a stupid question

    • alex says:

      You need to compile libplist and libiphone in their own folders. Do not mix the sources. Both libraries are connected to each other and to itunnel by the ln command you run at the end of each compilation.

      • Alex A. says:

        Ok, but when I compile libiphone in its own directory and run the “make” command i get an answer like this…

        make: *** No targets specified and no makefile found. Stop

        and im pretty sure all the files are there
        heres the ls

        alex@alex-laptop:~/build/libiphone$ ls
        aclocal.m4 config.log dev m4 swig
        AUTHORS configure doxygen.cfg Makefile.am
        autogen.sh configure.ac fdi Makefile.in
        autom4te.cache COPYING include README
        config.h.in COPYING.LESSER libiphone-1.0.pc.in src

        I see two makefiles, so i don’t know whats missing

        • alex says:

          Make sure you do this:
          ln -s plist-folder/ swig/plist
          ./autogen.sh
          ./configure
          before running make.

          • Alex A. says:

            i ran all 3 of those commands in ./build/libiphone
            they all seemed to run fine
            then I still get the same answer with the make command
            then i tried in ./libiphone
            and again the same result

            Sorry for the hassle, and thanks for the quick responses

  • Eshat says:

    You should correct Point 7:
    you missed a space between the paths…

  • Teddy says:

    Just thought I’d mention that sftp worked for me.

    I just did sftp -oPort=7777 root@localhost

  • CGB says:

    Great tutorial. One comment is that you do not need to make the symbolic links. Running ldconfig should be enough.

Leave a Reply

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Ivkin.Net :: where tech and candy come together