2

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 873:myserver.com:873), 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 873:myserver.com:873' . rsync://bt-backup@localhost/backup-bt-backup

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

doing:

sudo rsync -avv --progress --inplace --rsh='ssh -p 222 -L 873:myserver.com:873' . rsync://[email protected]/backup-bt-backup

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

3 Answers 3

5

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/ [email protected]:/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/ [email protected]:/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)

1
  • it has to be done through the daemon because the remote users are chroot jailed.
    – Malfist
    May 11, 2010 at 19:43
1

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

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

Don't forget to give it executable permissions: chmod u+rx ssh-connection.sh

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

sudo rsync -avv --progress --inplace --rsh='./ssh-connection.sh' . rsync://localhost/backup-bt-backup

Best of luck,
João Miguel Neves

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

From reference http://www.linuxquestions.org/questions/linux-software-2/rsync-ssh-on-different-port-448112/

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

If you need need to connect to rsyncd on the remote host:

ssh -p 222 -L 873:localhost:873 login@host -f -N -q && \
rsync [opts] rsync://rsync_user@localhost:873/ ...
2
  • I do need to connect to rsyncd on the remote host.
    – Malfist
    May 11, 2010 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, 2010 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .