Rsync Ssh utilizzando una porta non standard in Linux
Rsync è uno strumento per copiare i file localmente, verso/da un altro host tramite qualsiasi shell remota o verso/da un demone rsync remoto. Rsync è ampiamente utilizzato per il salvataggio dei dati.
Questo tutorial descrive come possiamo connetterci a ssh per copiare i dati usando rsync, se ssh è in esecuzione su una porta diversa.
Sintassi Rsync
L’utilizzo di base del comando rsync è:
rsync [options] src [dest]
Per impostazione predefinita, il comando rsync elencherà i file di origine se non viene fornita alcuna destinazione. Per esempio,
$ rsync /usr/
drwxr-xr-x 4096 2011/04/26 04:26:48 .
drwxr-xr-x 53248 2012/09/26 23:05:59 bin
drwxr-xr-x 4096 2011/04/26 04:27:37 games
drwxr-xr-x 20480 2012/09/08 19:17:32 include
drwxr-xr-x 69632 2012/09/26 23:05:50 lib
drwxr-xr-x 4096 2011/04/26 04:26:48 lib64
drwxr-xr-x 4096 2011/11/16 13:02:25 local
drwxr-xr-x 12288 2012/09/26 23:05:51 sbin
drwxr-xr-x 12288 2012/09/22 14:25:28 share
drwxrwsr-x 4096 2012/09/08 19:46:27 src
Ora per copiare localmente possiamo emettere il seguente comando
$ rsync -av file1 dir1/
sending incremental file list
sent 45 bytes received 12 bytes 114.00 bytes/sec
total size is 0 speedup is 0.00
Questo copierà il file chiamato “file1” nella directory “dir1”. L’opzione -v qui è solo per l’output dettagliato.
Rsync Ssh su una porta specifica
Se vogliamo connetterci a una macchina che esegue ssh su una porta specifica usando rsync allora possiamo eseguire la seguente sintassi
$ rsync --rsh="ssh -p1234" <sourcefile> user@host:/path/to/destination/directory
La porta su cui è in esecuzione ssh viene specificata utilizzando l’opzione -p come specificato sopra. Qui, la porta 1234 dovrebbe essere cambiata nella porta su cui è in esecuzione il server ssh. Un esempio funzionante della sintassi di cui sopra è
$ rsync -av --rsh="ssh -p22" file1 root@192.168.1.8:/mnt
The authenticity of host '192.168.1.8 (192.168.1.8)' can't be established.
ECDSA key fingerprint is fe:44:85:8c:2c:63:fb:d7:df:dd:27:17:45:04:28:9b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.8' (ECDSA) to the list of known hosts.
root@192.168.1.8's password:
sending incremental file list
file1
sent 84 bytes received 31 bytes 10.95 bytes/sec
total size is 0 speedup is 0.00
Questo copierà il file usando rsync+ssh, e ssh non è in esecuzione sulla porta predefinita (sebbene nell’esempio sopra, la porta sia quella predefinita, cioè 22).