If you want this to work from cron, you have several possibilities:
setup password-less ssh keys - not very secure
setup password-less ssh keys, but combine them with ssh ForceCommand in the authorized_keys file to limit the commands that can be run with that ssh key. See man sshd, google on "ssh ForceCommand"
setup passworded ssh keys, but combine them with keychain to keep the key in memory between sessions. I've written a blog post on this: ssh, ssh-agent, keychain and cron notes
Make sure you have a public key on your local machine that can log into the remote machine.(in this case the my ssh-key is "/home/myaccount/.ssh/id_rsa"
Specify local folder you want to sync with the remote, in my case "/home/myaccount/mysourcefolder"
Specify the destination folder full path in the remote server, in my case remoteaccount@remoteserver:"/home/remoteaccount/mydestinationfolder/"
Note:
--progress is to show progress for each file being copied
-a to transfer recusively all files in the mysourcefolder
发布评论
评论(3)
您不需要这样做 - 只需设置一对 ssh 密钥并将公钥放在远程系统的 .ssh 目录中。
然后你只需执行以下操作:(
注意,
-e ssh
已经成为默认值很多年了,因此你可以忽略它,除非你使用的是非常旧的版本。)请 此处有关设置密钥的“如何”指南。
You don't need to do that - just need to set up a pair of ssh keys and put the public key in the remote system's .ssh directory.
Then you just do this:
(Note that
-e ssh
has been the default for quite a few years now, so you can probably omit it, unless you're using a very old version.)There's a "how to" guide on setting up the keys here.
如果您希望它在 cron 中工作,您有几种可能性:
If you want this to work from cron, you have several possibilities:
如果您想远程复制文件:
注意:
我的命令如下所示:
If you want to copy files remotely:
Note:
My command will look like below: