For SSH you can do something like the following:
ssh -o ProxyCommand='nc -x localhost:$orport %h %p' example.com
Options can also be configured in your ~/.ssh/config
(or /etc/ssh/ssh_config
, or the equivalent on your OS) file:
Host example
Hostname example.com
ProxyCommand /usr/bin/nc -x localhost:$orport %h %p
Rsync can then use ssh as its remote shell and it will pick up the previous config:
rsync -e ssh example:path/to/files /dest
or, by directly passing arguments to the remote shell:
rsync -e "ssh -o ProxyCommand='nc -x localhost:$orport %h %p'" example.com /dest
Finally, you can use the RSYNC_CONNECT_PROG
environment variable to set up all future RSYNC invocations to use Tor (without having to manually specify it each time):
export RSYNC_CONNECT_PROG='ssh proxyhost nc -x localhost:$orport %h %p'
rsync example.com:/src /dest
Replace $orport
with the port you've got Tor's SOCKS proxy listening on.