问题原文
原帖链接 · Otto · CC BY-SA 4.0
I use rsync to deploy code to a remote server and currently I have passphrase for the security key. How can I add the passphrase in the rsync command without a prompt to use it in a script?
I don't use rsync-daemon.
My command:
rsync -vaz -e "ssh -i /root/.ssh/key.ppk" --chmod=ugo=rwX --omit-dir-times --no-perms . [email omitted]:/var/www/html
已采纳解答
原帖链接 · Jenny D · CC BY-SA 4.0
Make your security independent of the password of the private key, by instead restricting the usage of the key on the server side:
- Create a separate key pair used only for rsync. Make that private key passwordless.
- On the server, make sure that you have the script
rrsyncavailable. (It will usually be installed with the rsync package, probably in/usr/share/doc/rsync-VERSION/support. - Add the public part of the key to the target user's authorized_keys on the server. At the start of the line, add a load of restriction to enforce that the key can only be used from the correct server and only to rsync things to a specific directory, like this:
command="/path/to/rrsync /var/www/html/",no-pty,no-port-forwarding,no-user-rc,no-X11-forwarding,no-agent-forwarding,from="IPADRESS" ssh-rsa AAA[...]
Now you have a key that can be used only for one thing - to rsync things from one single server to the directory /var/www/html. The restrictions on the serverside mean that even if someone else gets hold of the key, the destruction they can wreak is very limited, and certainly far less than if they get hold of the password to a key that allows full access.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
