Terminal 101: Using rsync remotely

Every Monday, we’ll show you how to do something new and simple with Apple’s built-in command line application. You don’t need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type ’em out!

Last week, we talked about using rsync to transfer files from one location on your Mac to another (using rsync’s local syncing abilities); however, you can truly unlock the power of rsync when using it remotely to connect and transfer files from your local machine to a remote machine anywhere around the world. This remote syncing ability means that you could build an automated local-to-remote backup solution, or any other number of file transfer scenarios you can dream up. Continue reading, and we’ll show you how easy it can be to interface with a remote machine to sync files with rsync.

To use rsync remotely, we’ll assume that the remote machine already has SSH configured, and that you know the IP address. Note that by “remote,” the machine may be a part of your local network, or on a separate network accessible over the Internet (if you are accessing your machine over the Internet, you’ll need to do more advanced configuration on your router to accept incoming connections through a process called Port Forwarding. The port forwarding process is covered in Step 2 of an older article we published.).

Just as with the local rsync that we covered last week, all of the option flags that we used can still be used with a remote set up. The basic command for using rsync remotely is as follows:

rsync [options] [localPath] [user]@[host]:[remotePath]

We’ll replace options with the options flags that were covered in the last Terminal 101, replace localPath with the path to the directory or files that will be synced from the local machine; and on the remote side, we’ll replace user with the username available through SSH on the remote machine, and host with the IP Address of the remote machine. Finally, after the colon, we’ll put the remotePath of where we wish the synced files to end up on the remote machine.

What looks like a complicated process is not actually that complex at all. Like last time, we’ll sync the directory structure of a local folder on our machine to the remote machine that has a username of “Cory” and an IP Address of “192.168.1.20”.


So, if we wanted to do that, then the command would look like this:

rsync -dr -v ~/Documents Cory@192.168.1.20:~/Example

In the above command, we’re using the -dr flag to recursively sync the directory structure only; the -v flag lets us see what’s going on through verbose mode. We’ll be syncing the directory structure of the Documents folder to the remote destination at the file path “~/Example” (an Example directory in the user’s home directory on the remote machine).


Once you press enter, you will be asked for your SSH password, and then rsync will begin compiling the list of files that need syncing; then, right before your very eyes, will begin the transfer to the remote location. Once you get past the structure of the command, using rsync remotely is actually a very straightforward process — just like using it locally.

Note that if this is your first time connecting to your remote machine through SSH, you may be asked to add the RSA fingerprint (a special key that is used by SSH) to your local machine. Type “yes” (or “y”) and then enter to continue connecting to the remote machine should this appear.

What will you do with this power? Sure, you can use it for the occasional backup, but rsync has much more power than just that. This can be combined with other Terminal power tools to create an automated backup solution, or even a Dropbox alternative.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article’s author on Twitter.