Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old December 26th, 2006   #1
davidsiegel
A Carafe of Ubuntu
 
davidsiegel's Avatar
 
Join Date: Dec 2006
Location: Philadelphia
Beans: 82
Ubuntu 7.10 Gutsy Gibbon
HOWTO: Share folders between OS X and virtualized Ubuntu with Parallels and sshfs

I run Ubuntu 6.10 on my MacBook Pro using Parallels because sound and wifi are not supported on a native Edgy installation. Parallels has a "Shared Folder" feature that only works with a Windows XP client. Here is how I do folder sharing between OS X and Ubuntu, but it should work for any Linux or UNIX:
  1. In Mac OS X, before starting Parallels, go into the Sharing System Preference's pane and enable Remote Login by checking the box next to "Remote Login."
  2. In Parallels, go into Networking in your client preferences and enable Shared Networking.
  3. Start your Ubuntu client machine and login.
  4. Once in Ubuntu, install sshfs. sshfs is a filesystem built on top of ssh. Run the following in a Terminal (Applications > Accessories > Terminal):

    Code:
    % sudo apt-get install sshfs
  5. The sshfs install created a new user group called 'fuse'. If your Ubuntu username is 'joe', do the following to add joe to the fuse user group:

    Code:
    % sudo adduser joe fuse
  6. Log out of Ubuntu then log back in for these changes to take affect.
  7. Now we need to create a password-less ssh key so you can connect to your Mac OS X host via ssh without having to enter a password:

    Code:
    % sshkeygen
    When prompted for a password, just press return to leave the password blank.
  8. The IP address of your Mac OS X host on the shared network should be 10.37.129.2. If that host is unreachable in these next few steps, go to a terminal in Mac OS X and type 'ifconfig' and look for a similar IP address towards the bottom of the ifconfig output - near words like 'share' and 'bridge'. In my experience this address has remained constant.

    Code:
    % scp ~/.ssh/identity.pub osxusername@10.37.129.2:
    <Enter your OS X user's password when prompted>
    % ssh osxusername@10.37.129.2
    <Enter your OS X user's password when prompted>
    <You should now be logged into an OS X terminal via ssh>
    % mkdir .ssh
    % cat identity.pub >> .ssh/authorized_keys
    % rm identity.pub
    % exit
  9. Now we're ready to mount a shared folder. From a Ubuntu terminal, in your home directory (~):

    Code:
    % mkdir Documents_OSX
    % sshfs 10.37.129.2:Documents Documents_OSX
    And that should do it. Look inside Documents_OSX - it should have the same contents as your OS X Documents folder.
  10. If you would like to unmount your shared folder, you can either just log out of Ubuntu or do:

    Code:
    % fusermount -u Documents_OSX
  11. (Optional) I created this quick-and-dirty Python script that I saved as ~/bin/mount_sshfs (with executable permissions) and added to my session startup items (System > Preferences > Sessions > Startup programs tab):

    Code:
    #!/usr/bin/python
    
    import os
    import sys
    import getopt
    
    host = '10.37.129.2'
    
    mount_points = [('/Users/dave/Music', '/home/dave/Music'),
            ('/Users/dave/Documents', '/home/dave/Documents'),
            ('/Users/dave/Pictures', '/home/dave/Pictures')]
    
    def main(argv=None):
        if argv is None:
            argv = sys.argv
        try:
            opts, args = getopt.getopt(argv[1:], 'u', ['unmount'])
        except getopt.error, msg:
            print msg
            print 'for help use --help'
            sys.exit(2)
        mount_op = mount
        for option, a in opts:
            if option in ('-u', '--unmount'):
                mount_op = unmount
        mount_op()    
        return 0
    
    def mount():
        argv = ['/usr/bin/sshfs', None, None]
        for mount in mount_points:
            argv[1] = '%s:%s' % (host, mount[0])
            argv[2] = mount[1]
            cmd = ' '.join(argv)
            print cmd
            os.system(cmd)
    
    def unmount():
        argv = ['/usr/bin/fusermount', '-u', None]
        for mount in mount_points:
            argv[2] = mount[1]
            cmd = ' '.join(argv)
            print cmd
            os.system(cmd)
    
    if __name__ == '__main__':
        sys.exit(main())
    I save this as ~/bin/mount_sshfs and change its permissions to be executable. Whenever I login to Ubuntu, my OS X folder /Users/dave/Music is available in Ubuntu as /home/dave/Music.
davidsiegel is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:09 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry