How to Share Files between Mac and Linux the Easy Way

When I upgraded to Mac OS X Lion, I discovered that Apple unceremoniously removed FTP as a file sharing option. I understood why – FTP has little (if any) security. Still, it annoyed me, because I had ftp set up locally for convenience. Whatever, I wanted to get SAMBA working anyway, so it didn’t bother me. Accessing Linux from Mac proved straight-forward, but going the other way didn’t work out so well. After hours of battling with SAMBA I took a break and thought about ssh, and then I remembered SSHFS. Beautiful!

We’ll start with the hopefully easy part: accessing Linux from Mac. On Linux, set up SAMBA as normal. For the easiest time, set your security level to Shared. Only do this if you use a router or know how to configure a firewall. Now hopefully you will see your Linux machine in Finder and can go from there. If you opt for user level security, you can connect in the Finder. Hit Command-K and enter “smb://username@” Make sure you have your Linux machine set to use a static IP. Plenty of good tutorials exist on how to do these things if you need help.

Now we move on to the fun part: accessing Mac from Linux. You can try to get SAMBA working, but I had no luck with it. Instead, install SSHFS according to your distribution. Arch Linux would use “packman -S sshfs”, Debian and Ubuntu would use “apt-get install sshfs”, and Redhat/CentOS would use “yum install sshfs”. It’ll also install fuse. Remember to make sure the kernel loads the fuse module, using modprobe if necessary.

You now have to make a few changes on your Mac. Your Mac needs to use a static IP for this to work. To do this, open system preferences and go to the networking pane. Select your primary network interface, probably already done. Go to “Configure IPV4” and select “Using DHCP with Manual Address”. Enter in a suitable IP address, one which falls within your network. Now go to the Sharing preference pane and make sure you have Remote Login checked. Note the ssh information in the text box.

Close that an go to Linux. Add your Mac’s address to /etc/hosts to make things easier. We will call this host “mac” in this example. Create a directory with appropriate permissions to use as your mount point. We will use /mnt/mac for this example.

The time has finally come for some action. If you have a user named “apple” and you want to mount their home directory, you’d just type “sshfs apple@mac /mnt/mac” Enter your password. Easy as that! To unmount the directory, just use “fusermount -u /mnt/mac”.

To automate this, you will have to use an SSH key. You can then put an entry like this in your /etc/fstab:

sshfs#apple@mac:/users/apple /mnt/mac fuse defaults 0 0

Enjoy your lightning fast transfers. And if anyone really does know how to get SAMBA working with a mac, feel free to comment. Meanwhile, I feel content with this solution. I hope it helps someone.