2

I'm trying to make a backup .sh script to zip my files and to protect the zip archive with a password. For that, I'm using the zip package (apt-get install zip) and there's an encryption option accessible via the -e parameter. How can I specify the password directly? After typing the command, I need to enter a password, and the .sh-script will be run with cron jobs.

Here's my .sh file:

zip -r -e -q ~/var/backup/backup_`date +%Y_%m_%d-%H_%M` /var/www/

Here's the result with the -e parameter:

image

How can I automatically set a password and then retype it in a .sh-file (that will be ran with cronjobs)?

  • 1
    Having your password on your hard drive in plain text is insecure. I'm sure you know that - just thought I'd point it out. – Faheem Mitha Mar 28 '16 at 21:22
  • While it also shares the problem of being on the same hard drive, a lot of times people will place a password into an environment variable which can then be referenced by the script. That way, although someone may be able to view the script, they cannot access your user's personal files which set the environment variable to begin with. As for integrating this idea with cron, you will have to get a little creative. – tniles Mar 28 '16 at 21:39
  • Well it's a VPS and there's only one user: root, and also I've put the script in the ~/ folder (root) – Skrey Mar 28 '16 at 21:41
2

You can use the -P parameter to specify the password on the command line:

zip -r -e -q -P myPasswordHere ~/var/backup/backup_`date +%Y_%m_%d-%H_%M` /var/www/

You can find this sort of thing out by looking at the manual page for the program in question:

man zip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.