Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Every port on my server is blocked except port 222 which is were ssh connects too. This server is pretty much a backup server, and I have my clients rsync to it.

I do this by using ssh's port forwarding (-P 222 -L, however, I want to do this with just using the rsync command. Is that possible?

This is what I've been trying:

sudo rsync -avv --progress --inplace --rsh='ssh -p 222 -L' . rsync://bt-backup@localhost/backup-bt-backup

but it doesn't work because I try to log into localhost, instead of


sudo rsync -avv --progress --inplace --rsh='ssh -p 222 -L' . rsync://

lets me login through ssh, but rsync tries the remote host instead of the localhost where the port has been forwarded too

share|improve this question

If the server is running SSHd then you can just use rsync over SSH directly.

For instance I run things like
rsync -a --inplace some/dir/ user@remote.server.tld:/destination/dir/
all the time. There is no need to run rsync as a daemon or have port forwarding enabled as rsync will start a copy of itself using the SSH link and handle all synchronisation between itself and that instance over the SSH link too (and the remote copy closes as the connection is dropped so you don't end up with a bunch of zombie processes hanging around).

To talk over a port other than the standard one you just need to give rsync a little extra info about how it should manage the connection, like so:
rsync -a --inplace -e 'ssh -p 222' some/dir/ user@remote.server.tld:/destination/dir/

This is actually more secure (all the rsync communication is protected by SSHs secure transport, whereas with port forwarding everything is sent plain) and more convenient (no rsyncd needed, and you can use SSHs key based auth)

share|improve this answer
it has to be done through the daemon because the remote users are chroot jailed. – Malfist May 11 '10 at 19:43

rsync -av --progress --inplace --rsh='ssh -p8023' somefile user@host:somedir/


You only need port-forwarding if you want to use rsyncd on the remote host (with /etc/rsyncd.conf configuration).

share|improve this answer
I do need to connect to rsyncd on the remote host. – Malfist May 11 '10 at 19:35
in this case: ssh -p 222 -L 873:localhost:873 login@host -f -N -q && rsync [opts] rsync://rsync_user@localhost:873/ ... – aligot May 11 '10 at 20:04

Use a script to override ssh. Create a script with the following content:

#! /bin/bash
ssh -p 222 -L -l bt-backup myserver rsync --server --daemon .

Don't forget to give it executable permissions: chmod u+rx

This script ignores the arguments on purpose. It should be used as:

sudo rsync -avv --progress --inplace --rsh='./' . rsync://localhost/backup-bt-backup
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.