Before we start anything here, I’m going to give you a warning.
rsync can make a real mess of Mac OS files.
There, I said it. It wasn’t designed to handle resource forks or packages or the Mac’s icon storing arrangements. If you really need that, there’s another product called RsyncX which can do the job - but I’m not dealing with that app this time.
The man page describes it as a “faster, flexible replacement for rcp”. Essentially, it’s an app used for copying files either locally, or to other hosts. It can synchronize directories, or individual file, and can maintain file permissions and owners along the way. If you’re a UNIX geek, it’s for you.
I’m not going to go into the details of exactly what it can do, and how it work - rather, I’m going to go through the process of running the rsync daemon on your machine. This will allow you to access your rsync “shares” from any other machine on your network at any time.
Let’s begin.
1. First thing you want to do, is make sure you are an administrator on your mac. There’s not much point continuing if you’re not. You may need to use sudo to create some of the files below.
2. Open up Terminal and cd to /etc/xinetd.d
Here we’ll create a service definition which will allow the daemon to start (through xinetd) whenever the machine is started - or more specifically, whenever its called.
3. Create a new file called: rsync
I prefer to use vi (or vim), since it’s UNIX tradition to use apps that are difficult to use.
In this file, insert the text exactly as follows:
# default: off
# description: The rsync server is a good
# addition to an ftp server, as it
# allows crc check summing etc.
service rsync
{
disable = no
log_on_failure += USERID
socket_type = stream
user = root
server = /usr/bin/rsync
server_args = --daemon
wait = no
}
This creates a service called rsync which uses the app /usr/bin/rsync with the arguments --daemon.
Save the file and exit your editor.
4. Check the directory and make sure the owner of the file is root, the group is wheel, and the permissions are rw-r-----.
5. cd to /etc
6. Create a new file called rsyncd.conf
Here we create definitions for the various “shares” the rsync daemon will host.
[root] path = / hosts allow = 192.168.1.1 uid = root gid = wheel read only = false comment = Root volume
Again, I won’t explain exactly what all the options are, but essentially, this creates a share called root which points to the root path of the volume ( / ), is readeadable/writeable, only allows connections from the host at 192.168.1.1, and uses root permissions. I wouldn’t grant permissions like this to a host unless you trust that host a whole lot.
If you’re not sure you want to be as extreme as the example above, try:
[websites] path = /web_sites comment = Web Site Directory for OS X
Save the file and exit your editor.
7. Check the directory and make sure the owner of the file is root, the group is wheel, and the permissions are rw-r-----.
8. Now we have everything we need run. The only thing left is to HUP xinetd. You have two options here - restart the machine, or send a HUP signal to xinetd and force it to reload it’s settings, thus starting rsyncd.
If you don’t want to restart, HUP-ing xinetd is a simple process:
run: ps -A | grep xinetd
The results will look like this:
PMG5:/etc dangelovich$ ps -A | grep xinetd 322 ?? Ss 0:00.02 xinetd -dontfork -stayalive -inetd_compat -pidfile /v 398 p1 S+ 0:00.00 grep xinetd
That first number - 322 - is the PID (Process ID) of xinetd. Now we need to tell it to HUP:
PMG5:/etc dangelovich$ sudo kill -HUP 322
This will be more or less the same on your machine, except the PID will be different.
9. The final step is to test the service. If you port scan (or nmap) your machine, you’ll see that the default rsync port is open (port 873). You may also want to test the connection by running a basic rsync:
rsync -axv rsync://192.168.1.2/root/etc/motd /tmp/