LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-10-2014, 11:50 AM   #1
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Rep: Reputation: Disabled
GPG Encryption Script Issues


Hey Guys,

I wonder if someone could help shed some light on the problems I'm having with my script.

I'm pretty new to BASH and have been learning loads lately, so I'm actually quite happy with how far I've come on my own, however I have a question..

I'll put my script below. So my question on most of it, is have I done it the 'right' way and could I have made it simpler? Or is there a nicer way of doing anything?

My second question is specifically with the GPG bit, although the password is stored in the file /root/.gpgpass - it still pops up and asks for the password if it's not run within a couple of hours.. almost like it's only caching the password and when it expires it requires human interaction. Is there another way of doing this without putting the password in plain text within the script and without any human interaction?

Code:
#!/bin/bash

#Declare the variables... change these as needed if the script is run on another server or the locations change.
HOST=ftp-server
USER=ftpxfer
PASS=pass
FILE=test.csv.gpg
FTPLOG=/tmp/ftplogfile
OUTPUT=/scripts/test.csv

ftp -inv $HOST <<! > $FTPLOG

quote USER $USER

quote PASS $PASS

get $FILE

bye
!

if fgrep "226 Transfer complete" $FTPLOG ; then
	echo "FTP TRANSFER SUCCESS"
else
	echo "FTP TRANSFER ERROR - Send email could go here."

fi

gpg --passphrase-file /root/.gpgpass --output $OUTPUT --decrypt $FILE

cp $OUTPUT /storage

exit 0
 
Old 06-10-2014, 05:13 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
I share with you my scripts as well (encrypt and decrypt). I use the scripts to encrypt whole drives. Typically terabytes on a file by file basis and then gpg sign the sha1sum.txt files.

One thing you can do is use the expect command in your script. I've used the pexpect python library on one of my side projects. It executes a script call cert.sh and then when there's user prompt it automates responses.

From the Esoteric Options docs on GPG here's a quote.

Quote:
--passphrase-file file
Read the passphrase from file file. Only the first line will be read from file file. This can only be used if only one passphrase is supplied. Obviously, a passphrase stored in a file is of questionable security if other users can read this file. Don't use this option if you can avoid it. Note that this passphrase is only used if the option --batch has also been given. This is different from gpg.
Your gpg command is not using the --batch option so it's likely not using that option at all. The gpg-agent is likely caching your password and you're prompted after a set expiration. If you need to automate gpg why not just remove the password from the key you're using? It's roughly equivalent. Also you shouldn't need to enter a passphrase at all if you're encrypting. But you would need to if you're signing just FYI.

SAM

Last edited by sag47; 06-10-2014 at 05:14 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Encryption with openssl and gpg szim90 Linux - Security 1 10-22-2007 03:13 PM
gpg encryption for skype crashsystems Linux - Security 3 07-12-2007 12:17 PM
which encryption should I use, gpg? Melsync Linux - Security 4 07-06-2006 05:26 AM
gpg filename encryption ??? rino.caldelli Linux - Security 2 02-26-2006 06:34 AM
gpg / pgp encryption pteren Linux - Software 8 07-26-2003 03:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration