If you want to mirror a remote directory via SSH, you may want to use the wonderful rsync command.
The rsync executable has many options, so, which is the correct option list to make an exact copy of a remote directory, maintaining permissions, ownerships, timestampts, copying only the modified files, and updating only the pieces of modified files?
Let me begin with an example. We want to full mirror the directory /mystuff on server 184.108.40.206 into /mystufflocal. The files deleted on 220.127.116.11 from the previous rsync will be removed locally too, so pay attention! If you don’t want to locally remove deleted files you can remove the “–delete” option.
If you want to compress the stream in transit you can add the “-z” option.
All we have to do is:
rsync -vartuh –inplace –delete –progress –stats -e “ssh -carcfour128”
The trailing slashes are important because are used by rsync to understand precisely what should be transferred and where.
If your SSH connection is slow, it may depends on your SSH server that is executing reverse DNS lookups to try to identify your details.
Try setting the parameter below to your /etc/ssh/sshd_config and restart your ssh server daemon:
It worked perfectly for me, it may work perfectly with you too.
Sometimes you may need to forward remote traffic to a local host through a SSH connection. In other words you can bind a given TCP port to a server running SSH and make remote clients connecting to it, letting the traffic to be redirected to a local server.
You may need to add the parameter GatewayPorts clientspecified to /etc/ssh/sshd_config on the SSH server and restart sshd. This is to enable ssh clients to bind remote connections on a given ip, otherwise you can only connect to the remote port just from 127.0.0.1.
At this point, let me do an example:
If you have the given situation, you can execute the following command to bind the TCP port 18443 on the remote server:
ssh -l root 192.168.1.2 -R:18443:18.104.22.168:18443
Now, you can apply your changes:
You can even do the reverse, letting local traffic flowing to an external host, passing through a SSH connection.
Let me do another example:
If you have the given situation, you can execute the following command to bind the TCP port 18443 of your computer to the remote server:
ssh -g -l root 192.168.1.2 -L18443:192.168.1.3:18443
Now, apply your changes: