FREN

#FF00AA


24 jun. 2007

How to “simply” copy files between your Macs

@apple@

I had an epiphany yesterday that the most reliable way to copy files between my local network’s computers should be Transmit droplets using FTP over SSH — with the advantage that it’s secure, and doesn’t risk sending my password in clear text over wifi.

So I tried it and, lo and behold… it was way too slow: first the droplet launches, then it launches Transmit if it wasn’t running already, then it connects (and it seems to be rather slow connecting over SFTP), and Transmit takes some space in the dock… Too cumbersome.

Then I realized I could use the command line for that, encased in a little bit of AppleScript. I wrestled with it for a while, spending two hours trying to make Keychain Scripting work before I realized I could not send the password to scp from the command line and I had to create SSH keys. Which is more secure, for sure, but also much more of a hassle to setup — not that I personally mind, but it’s going to make the instructions below much more daunting.

So I better entice you, first. Here’s what it looks like:

Okay, that’s not very spectacular. But imagine you can just drop a file or folder or several of each on one of the icons, and they’re instantly copied to that computer’s desktop (or any other place — you can create one droplet per destination). No waiting for the Finder to mount a network share (and hoping it succeeds) or for an FTP app to launch. No keeping iChat open just to use Bonjour file transfers (which require confirmations, despite Chax, for zip files and applications). No buying expensive shareware, and no running unreliable freeware. It’s all achieved with the magic of Unix.

Oh, and it works perfectly with applications, links or clippings. And you can even directly drop a link from Safari if the droplet is in the dock (but not on the desktop).

 

On to the setting up part. Which will probably deter most of you, while the others will just find the instructions obvious. So I’m basically just writing this for my own future reference. But, even if you don’t know anything about Unix, you can perfectly manage with the following walkthrough, by copying and pasting exactly what’s written.

Let’s say you’ve got a network of four computers: ComputerA, ComputerB, ComputerC and ComputerD. (Those names are defined in the Sharing preferences name, and if they’ve got spaces and other special characters in them you might as well rename them now, or be prepared to type IP addresses instead of the names in all of the following.)

First you need to enable SSH on each computer in the Sharing preferences pane (it’s called “Remote Login”):

If your firewall is enabled, make sure the port is open, too (it should automatically be):

Start Terminal on ComputerA to create the SSH key that will enable you to log from one computer to the other without having to type your password (if your network addresses don’t start with 192.168, change accordingly — but make sure you don’t forget the space after the closing double-quote):

mkdir ~/.ssh

ssh-keygen -f ~/.ssh/local -t rsa -N ""

echo -n ’from="*.local,192.168.*;" ’ >> ~/.ssh/authorized keys2

cat ~/.ssh/local.pub >> ~/.ssh/authorized keys2

chmod 0600 ~/.ssh/authorized keys2

(Security note: when we’re done, someone who has access to your computer, logged in under your username, and connected to your home network, will be able to access all your other computers on the same network. Which I find perfectly acceptable, but you may be more paranoid than me. In which case you should see a doctor.)

Copy the SSH keys to the other computers (YourUserName is the “short user name” defined in the Accounts preferences pane on each computer; in my case it’s the same on each, but it may not be for you):

scp ~/.ssh/local ~/.ssh/local.pub ~/.ssh/authorized keys2 YourUserName@ComputerB.local:/Users/YourUserName/.ssh

scp ~/.ssh/local ~/.ssh/local.pub ~/.ssh/authorized keys2 YourUserName@ComputerC.local:/Users/YourUserName/.ssh

scp ~/.ssh/local ~/.ssh/local.pub ~/.ssh/authorized keys2 YourUserName@ComputerD.local:/Users/YourUserName/.ssh

Now, we’ve got to run SSH manually one first time so that your computer knows that the others can be trusted (there might be a command-line option to ignore known hosts, but I don’t know it — advice is welcome). After each line you should have to answer “yes” (unless you’ve already used SSH before):

ssh -i ~/.ssh/local ComputerB.local /usr/bin/true

ssh -i ~/.ssh/local ComputerC.local /usr/bin/true

ssh -i ~/.ssh/local ComputerD.local /usr/bin/true

Then (and that’s where it gets kinda tedious) you’ve got to move over to ComputerB’s keyboard, launch Terminal, and do the same (well, you could be imbricating ssh calls, but that’ll be left as an exercise to the reader):

ssh -i ~/.ssh/local ComputerA.local /usr/bin/true

ssh -i ~/.ssh/local ComputerC.local /usr/bin/true

ssh -i ~/.ssh/local ComputerD.local /usr/bin/true

Then repeat for ComputerC and ComputerD and we’re done with Terminal. Download this AppleScript application, edit it with Script Editor, and change the first three lines; duplicate and edit as many versions of the droplet as you need, and you’re all set. (If you don’t have Growl, you’ll either need to install it — which you should — or remove the three corresponding blocks of AppleScript code.)

Want to know when I post new content to my blog? It's a simple as registering for free to an RSS aggregator (Feedly, NewsBlur, Inoreader, …) and adding www.ff00aa.com to your feeds (or www.garoo.net if you want to subscribe to all my topics). We don't need newsletters, and we don't need Twitter; RSS still exists.

Legal information: This blog is hosted par OVH, 2 rue Kellermann, 59100 Roubaix, France, www.ovhcloud.com.

Personal data about this blog's readers are not used nor transmitted to third-parties. Comment authors can request their deletion by e-mail.

All contents © the author or quoted under fair use.