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
If the server is running SSHd then you can just use
rsync
overSSH
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)
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:
Use a script to override ssh. Create a script
ssh-connection.sh
with the following content: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:
Best of luck,
João Miguel Neves