WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: password protecting a file via bash script ?  (Read 6405 times)

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
password protecting a file via bash script ?
« on: May 25, 2017, 09:31:17 PM »
Hi all,

I'm trying to figure out how to password protect a file from a shell script, before uploading it to google drive for offsite backup.

I can't find reference about passing a password to bcrypt in the bcrypt command, it seems to want interaction...

Any comments and suggestions welcome.

Thanks.
Live long and prosper.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11630
Re: password protecting a file via bash script ?
« Reply #1 on: May 25, 2017, 09:41:14 PM »
Hi remus
Try this:
Code: [Select]
yes PASSWORD | bcrypt FILENAME

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: password protecting a file via bash script ?
« Reply #2 on: May 25, 2017, 09:58:58 PM »
Thx rich, works well.

Does bcrypt have a file integrity testing option like 7zip does ?

I just realised that it would be great to be able to run an integrity test on the file before uploading it.

Live long and prosper.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11630
Re: password protecting a file via bash script ?
« Reply #3 on: May 25, 2017, 10:08:43 PM »
Hi remus
Quote
Does bcrypt have a file integrity testing option like 7zip does ?
The programs usage doesn't mention it:
Code: [Select]
tc@box:~$ bcrypt
Usage is: bcrypt -[orc][-sN] file1 file2..
  -o Write output to standard out
  -r Do NOT remove input files after processing
  -c Do NOT compress files before encryption
  -sN How many times to overwrite input files with random data
tc@box:~$

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: password protecting a file via bash script ?
« Reply #4 on: May 25, 2017, 10:42:38 PM »
I noticed that too Rich.

So I've done a little searching and discovered zip-unzip.tcz

And have come up with this.

zip -P password file.zip file.txt (Will create a password protected file with password as the password)

unzip -t -P password file.zip (Will test my archive, and I'm passing the password to it)

These commands will do for what I need. I know this approach has a few security flaw's. But It will do. I'm not dealing with national secrets.
Live long and prosper.