68

I am using:

 gpg --gen-key

Is there a better way to create a PGP key? What does this program want? A fully slammed server?

Not enough random bytes available. Please do some other work to give the OS a chance to collect more

halfer
  • 19,824
  • 17
  • 99
  • 186
Tampa
  • 75,446
  • 119
  • 278
  • 425
  • 2
    Also see [this other SO question][1]. [1]: http://stackoverflow.com/questions/11708334/pgp-asymmetric-not-enough-random-bytes-available-please-do-some-other-work-to – BellevueBob Sep 04 '12 at 20:18
  • 1
    How is this a programming question? I could see it as a system administration question or an end-user software usage question, but neither of those are topical here. (Also, it's a bit sad to see the answer that makes sense on modern hardware -- using rng-tools to bridge the TRNG to /dev/random -- buried down at third place). – Charles Duffy Nov 10 '14 at 16:08
  • just use ls -R / simple. no need to install any bloatware – alcedo Sep 13 '17 at 14:20

5 Answers5

83

Depending on your system hardware, you might have more reliable success using a bridge between the hardware TRNG (True random number generator) and the kernel entropy pool.

I have found a remarkable speed increase by using rng-tools in the universe repository, which can be installed with Synaptic or another GUI package manager, or via the command-line:

sudo apt-get install rng-tools
kylehuff
  • 5,177
  • 2
  • 34
  • 35
  • 9
    gpg hung for hours, no matter how much I moved the mouse, etc. Installing this package allowed gpg to finish in seconds, without moving the mouse. – Ross Smith II Mar 24 '15 at 21:20
  • Do you just have to install it, or run one of the tools while it's going? – Brōtsyorfuzthrāx Feb 03 '16 at 08:23
  • Just installing it didn't work for me (unless I have to restart my computer first). Running the software updater seems to help sometimes, heh, heh. – Brōtsyorfuzthrāx Feb 03 '16 at 08:29
  • 2
    Simply installing this package on ubuntu 14.04 amd64 had my `gpg --gen-key` finish in seconds as well, whereas previously it had hung for many minutes. Thanks! – seanp2k Feb 23 '16 at 20:23
  • this worked for me, where everything else like long find failed – Vitomakes Sep 14 '17 at 14:53
  • 4
    .. and Run `sudo rngd -r /dev/urandom` before generation! – Solo.dmitry Jan 25 '18 at 11:24
  • Simply installing it worked for me. This should be the accepted answer. Thanx!! – Napster_X May 13 '18 at 17:35
  • Installing `rng-tools` and running `sudo rngd -r /dev/urandom` worked for me – M. Atif Riaz Nov 06 '18 at 13:54
  • On a VM, `rng-tools` will probably not be much help because it doesn't have access to the cpu's TRNG. [Use `haveged` instead](https://stackoverflow.com/questions/11708334/pgp-not-enough-random-bytes-available-please-do-some-other-work-to-give-the-os/21705999#21705999) – wisbucky Jul 09 '19 at 01:34
  • yum install rng-tools and sudo rngd -r /dev/urandom works for RHEL. – NGBeginner Aug 25 '20 at 06:13
34

Executing the following command in the background works for me:

sudo find / -type f | xargs grep somerandomstring > /dev/null
munyengm
  • 15,029
  • 4
  • 24
  • 34
17

You can move your mouse around, browse the internet, play a game, leave your computer on overnight. There are many many ways to generate random bytes. You don't need to babysit the gpg process.

EDIT: I should clarify: you don't need to pay attention or even type into the terminal that gpg is running in. (And it's a really bad idea to type into that terminal anyway.)

If you're on a remote server, and cannot otherwise generate work, you can try this: http://packages.debian.org/squeeze/stress. Use caution, though.

Infiltrator
  • 1,611
  • 1
  • 16
  • 25
  • 3
    I am using a remote server. How lomng does it take to generate? – Tampa Sep 04 '12 at 06:22
  • It's difficult to put a timeframe on it. But you can try firing up a whole heap of different processes to load it. A good one is the 'stress' package: http://packages.debian.org/squeeze/stress – Infiltrator Sep 04 '12 at 06:24
  • 1
    It just doesn't work. The message "Not enough random bytes available..." is continuing to appear with different values of bytes (sometimes less, sometimes more) required. – dE fENDER Jul 06 '17 at 10:38
  • @dEfENDER it sounds like you are restarting the gpg process, if the number of bytes is going down *and* up. You have to leave it running, while you generate more entropy. – Infiltrator Nov 03 '17 at 02:33
  • No. I do not restarts the process. It just sometimes writes +++ and the message about data to console. If I leave the process it will do nothing. Some methods of manupulating huge data in other consoles are works sometime and it saves... – dE fENDER Apr 05 '18 at 13:32
  • 2
    Running `ls -alR /` a couple of times did the job for me. – cherouvim Apr 10 '19 at 08:59
4

I found that just moving the program to the background worked even over an ssh interface:

  1. move the task to the background (Ctrl+z)
  2. perform a few short tasks (cd ~ && ./my-time-waster.sh)
  3. move the task to the foreground (fg)
  4. wait a minute or two

I'm using CentOS5 and CentOS6.

JellicleCat
  • 28,480
  • 24
  • 109
  • 162
2

Try using rngd, but without the -r /dev/random you will often see people advise (which will lead to insecure GPG keys). On my machine, just installing rngd installs a daemon which fills up my entropy quickly, and securely.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Chris Jefferson
  • 7,225
  • 11
  • 43
  • 66
  • I had to run rngd with `rngd -r /dev/urandom` before I used gpg in order to get it working in VirtualBox – Tomas M Jan 29 '18 at 16:56