Wie kann ich mit einem privaten Schlüssel rsyncieren?

7822
Richard

Ich versuche, von meinem MacOS-Computer auf einen Ubuntu-Server zu rsyncieren, der unter Windows Azure ausgeführt wird. Um ssh dazu zu machen, muss ich folgendes tun:

 $ ssh -i myPrivateKey.key -p 22 me@me.cloudapp.net 

Ich denke, die Schlüsseldatei könnte ein öffentlicher X509-Schlüssel sein, wenn das hilft (tut mir leid, ich bin kein Sysadmin). Jedenfalls kann ich mit dem obigen Befehl erfolgreich ssh.

Jetzt möchte ich Dateien mit dem Remote-Server synchronisieren. Muss ich die .keyDatei irgendwie als Option angeben?

Ein normaler Rsync-Befehl schlägt fehl:

$ sudo rsync -avz -e my/file me@me.cloudapp.net:/my/path rsync: Failed to exec my/file: Permission denied (13) rsync error: error in IPC code (code 14) at /SourceCache/rsync/rsync-42/rsync/pipe.c(86) [receiver=2.6.9] rsync: connection unexpectedly closed (0 bytes received so far) [receiver] rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [receiver=2.6.9] 
6

1 Antwort auf die Frage

9
grawity

The command fails not because of wrong keys, but because you're telling rsync to run my/file instead of ssh (by using the -e option, which picks up the word following it). Remove the -e option first.

Since rsync normally uses ssh to connect, you can configure both to always use a particular key for connecting to cloudapp. For example, put this at the top of your ~/.ssh/config file:

Host me.cloudapp.net Username me IdentityFile ~/my-cloudapp-key.key IdentitiesOnly yes 

The Username me part will also let you skip adding me@ when using ssh or rsync. Plain rsync -avz my/file me.cloudapp.net:/my/path will work.


Note: SSH keys are not X.509 certificates; they're just plain RSA or ECDSA keypairs without any additional information.

Auf Ubuntu scheint es sich um "Benutzer" anstelle von "Benutzername" zu handeln Thomas Weller vor 8 Jahren 1
Wenn Sie einen anderen Port als 22 benötigen, können Sie mit `Port 8023` eine Zeile hinzufügen. Alternativ müssen Sie --rsh = 'ssh -p8023'` direkt in die Befehlszeile einfügen. TheStoryCoder vor 7 Jahren 0