I want to download the file from sever by using cron job, so I need to use
scp command without giving password by keyword.
How do I do so?
First step is to generate a private-public key pair on the machine you copy from:
You can go with the defaults, and make sure you don't provide a password for usage. This can take a bit of time.
Second step, after the key generation has finished, is to copy the public key to the server using:
with the appropriate
server. For this you need the password of
username doesn't have a password, you can copy the file with the public key via the root account, but it is much more easy to temporarily create a password for the account and use
Third step: test whether the installed public key is working using:
ssh username@server or
scp somefile username@server:/var/tmp
Fourth step: add a cron job (
crontab -e) on the client machine:
15 23 * * * scp username@server:/path/on/server/downloadfile /local/destination 17 23 * * * scp /local/source/somefile username@server:/path/on/server/uploaddirectory
Which will copy the file
/path/on/server/downloadfile every day at 11:15 PM from the server and two minutes later starts uploading
Things to consider:
usernameaccount so that it only allows
rsyncusing the above ssh key pair) is more efficient.