views:

28

answers:

2

Hi Everyone, really new to linux scripting so i figured i would ask rather than waste time pulling my hair out.

i have a simple script that backs up the contents of a folder on my linux box and moves it to S3 storage, i would like this script to create a zip file and password protect it without any intervention from me.

i got it down to

zip myarchive.zip /var/www/* -e 

but cannot work out where i should put the password to stop it prompting me.

thanks kris

+2  A: 

Doing that is a security risk as it means your password will be written in cleartext in your script.

For this reason, zip refuses to work that way. It wants the input from the keyboard, not your script or a file.

I'm not aware of a workaround.

On the other hand, at least the zip in my Ubuntu distribution offers a -P password option which, I think, allows you to enter the password right on the command line. The documentation surrounds this option with the appropriate warnings.

Carl Smotricz
spot on for this although as mentioned its a security risk, id rather take the chance of having the password in the script than passing a zip file over the internet unsecured.you can script it in the following wayzip myarchive.zip /var/www/* -P yourpasswordand it works perfectly.thank you!
Kristiaan
Great! Now that I know your password is `yourpassword`, all I need to find out is where your computer lives! ;)
Carl Smotricz
Having the password in a script is one problem, but another, possibly bigger, problem is that while zip is running, everyone on the same machine can see the password in the output of ps -ef
ammoQ
A: 

You could also use the security features provided by the file system. This is indeed another story, but it does protect your information in most cases.

So I guess doing a chown and chmod on your archive after creating it will prevent unwanted users from accessing the file, if all you need is a file that can only be read by a certain group. The main advantage is that there's no need to memorize a password here.

spyked