LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-29-2011, 05:05 PM   #1
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Rep: Reputation: 18
What's best practise to GPG single large file with keyfile on USB stick?


Hi,

I have a large file I would like to encrypt with GPG and move onto the cloud or public storage, etc. so it can't be read and or tampered with without be knowing when I decrypt it.

I normally use:
$ gpg -c desktop2011.img
Passphrase: ****

and this creates a desktop2011.img.gpg file which works fine.

But what I want is no passphrase and just have a small .key file I can safely store on a USB stick.
What's the best practice for doing this with GPG?

One more thing...
I actually have a few (notebook1.img, notebook2.img) files too. I want all these encrypted with different keys on the USB stick, I don't want one master key for all of them if this makes sense.
 
Old 12-29-2011, 06:16 PM   #2
BlackRider
Member
 
Registered: Aug 2011
Posts: 295

Rep: Reputation: 101Reputation: 101
Quote:
But what I want is no passphrase and just have a small .key file I can safely store on a USB stick.
What's the best practice for doing this with GPG?
I would use openssl for this.

The way you apply this depends on your security model, but basically you encrypt things doing:

1- Create a random key.
openssl rand -base64 32 > keyfile

2- Encrypt the thing using openssl:
openssl enc -aes-256-cbc -pass file:keyfile -in clear_file -out encrypted_file

This is a dirty way, of course. You can have a passphrase stored in hex, and an IV (Initialization Vector) saved in another file, which would be more "elegant" that having just a plain-text keyfile with a random generated password.

Remember that the keyfiles are vulnerable if they are not physically secured. If you have them in a USB drive and it gets stolen, they have the key as it is. Read the manuals and use your brain, having keyfiles around is good because you avoid keyloggers and the like, but it is bad because the "passphrase" can be stolen.

Last edited by BlackRider; 12-29-2011 at 06:47 PM.
 
Old 12-30-2011, 12:44 AM   #3
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
Thanks BlackRider, I have used openssl for a similar thing in the past.

But still wondering the best practices for GPG doing this as GPG is more suited for large files (and has builtin compression etc).
 
Old 01-03-2012, 12:32 PM   #4
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
The -c flag with gpg will ask for a passphrase, which is what you are saying you don't want. Normally, one can just use the -e flag instead. This way the only pass phrase will be the one on the private key that will be needed when you decrypt. You can also create a signature and even a detached ascii signature that you can use to verify the file integrity using your public key. See the following link for details on the command flags: http://www.gnupg.org/documentation/manpage.en.html
 
Old 01-03-2012, 05:39 PM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
If you don't want to go to the trouble of creating a public/private key-pair for the purpose then you can use the --passphrase-file or even --passphrase-fd option along with the '-c' option to avoid having to enter the passphrase manually

I use this approach to copy & encrypt a second copy of my daily user-backup incremental tar files to a usbkey

e.g.

Code:
#!/bin/bash

cd /var/backup

while read file
do
  test -f "/mnt/backup/${file}.gpg" \
    || gpg --passphrase-fd 0 \
           --output /mnt/backup/${file}.gpg \
           -c "$file" <<< 'passphrase goes here'
done < <( find . -type f )
Obviously anyone who can read the script will be able to see the passphrase, but for my usage case that is not an issue as it's only intended to protect the data on the usbkey and anyone who can read the script (700 root:root) can read the originals anyway.

There's also a "--passphrase string" option that'll let you put the passphrase directly on the command line but I wouldn't recommend that one as it'll be exposed on a "ps -ef".
 
Old 01-03-2012, 07:16 PM   #6
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
GazL,

This is what I was thinking. But to have a passphrase that is something like 1000 chars long (like a key).
 
Old 01-04-2012, 03:12 AM   #7
BlackRider
Member
 
Registered: Aug 2011
Posts: 295

Rep: Reputation: 101Reputation: 101
Quote:
But to have a passphrase that is something like 1000 chars long (like a key).
What a waste. I think such a big key would have its half end unused for cryptographic purposes. An AES-256-CBC algorithm needs a key of 256 bits only, everything above that would be wasted. A 1000 character key is over 5000 bits.

Of course, I am not an expert, nor have I looked so deeply in the OpenSSL implementation. Should this be false, please tell it to us.

Last edited by BlackRider; 01-04-2012 at 03:16 AM.
 
Old 01-08-2012, 04:12 PM   #8
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by BlackRider View Post
What a waste. I think such a big key would have its half end unused for cryptographic purposes. An AES-256-CBC algorithm needs a key of 256 bits only, everything above that would be wasted. A 1000 character key is over 5000 bits.
This was for the passphrase I was referring to. But if I could store the raw 256bit key in a .key file instead that would be better.
 
Old 01-17-2012, 06:14 AM   #9
ryran
LQ Newbie
 
Registered: Dec 2011
Location: Abu Dhabi
Distribution: Fedora
Posts: 19

Rep: Reputation: Disabled
Well, you've been given ideas about how to go about things with openssl (the simplest way IMHO) and with gpg's symmetric encryption .... so I'll give a quick primer on using gpg with keys, as it was originally intended.

While I don't particularly think it's necessary to use different keys to encrypt your different files, it is possible, so I'll show one way.

Code:
USB="insert path to the drive you're using to store your keys here, e.g. /media/myusb"

for d in .gpg1 .gpg2 .gpg3; do
    mkdir $USB/$d; chmod 700 $USB/$d
    gpg --homedir $USB/$d --gen-key
    echo 'default-recipient-self' >> $USB/$d/gpg.conf
done
So what this does is create 3 new directories in the "USB" directory you specify and then tells gpg to generate new public-private keypairs using each directory (in turn) as it's home directory (instead of the traditional ~/.gnupg). It also sets each directory's config file to use its first key as its default-recipient (so that you don't have to type in -r or --recipient).

Regarding --gen-key:
For key type, choose the first choice -- "RSA and RSA (default)".
For key size, you're welcome to jack it up to 4096, since I get the feeling you might be a bit paranoid.
Name, email, & comment are only important if you're going to be distributing the public half of this keypair to others, so they can encrypt things to you; for this explanation, it doesn't matter what you type.

Once that's done, you're ready to use them. But first, a note: when starting out with gpg, I found it was great to run it with -v or -vv (verbose) in order to get a better idea of what was happening, so I recommend adding that to your command-lines (or add 'verbose' to gpg.conf).

Code:
USB="whatever"
gpg --homedir $USB/.gpg1 --encrypt notebook1.img
gpg --homedir $USB/.gpg2 -e notebook2.img
gpg --homedir $USB/.gpg3 -e desktop2011.img
You end up with three files, encrypted with three different keys. In order to decrypt them, you'll need to use the same homedir setting (or you could import all the keys into one keyring).

Code:
gpg --homedir $USB/.gpg2 -d notebook2.img.gpg
Don't worry if you get mixed up about which keys you used for which files; it's simple enough to figure out, as long as you still have the keys. Obviously, if you only have 3, at most you have to give it 3 tries, but if you have more ...
Code:
gpg --homedir $USB/.gpg3 -d notebook2.img.gpg
gpg: encrypted with RSA key, ID B1CCA8F8
gpg: decryption failed: secret key not available

keyid=B1CCA8F8
for d in .gpg1 .gpg2 .gpg3; do
    if gpg --homedir $USB/$d --list-keys | grep -q $keyid; then
        echo "key $keyid is in $USB/$d"; break
    fi
done
PS: If you give up your requirement of always storing keys on usb, the best gui gpg-key-management tool I've seen is a gnome-app called seahorse and it would be simple enough to use to create a few different keys. As a bonus, if you keep the keys on your computer instead of in a usb drive, you could install seahorse-plugins and use nautilus to encrypt/decrypt them via its right-click menu.
 
1 members found this post helpful.
Old 01-17-2012, 04:33 PM   #10
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
Thanks ryran.
I will try seahorse and have a look if it can work for me. Looks good.
 
  


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
[SOLVED] gpg: WARNING: unsafe permissions on configuration file `/home/b/.gnupg/options' gpg: widda Mandriva 9 07-30-2018 07:49 AM
How to speed up single large file copying? edenCC Linux - Server 4 04-22-2010 11:24 AM
GPG: Bad session key gpg between gpg on linux and gpg gui on windows XP konqi Linux - Software 1 07-21-2009 09:37 AM
I/O error when copying large file from Memory Stick airman99 Linux - General 3 08-22-2005 09:26 AM
Large (512mb) USB stick doesn't work with SuSE Personal 9.1 Napalm Llama Linux - Hardware 3 12-12-2004 05:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:58 AM.

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