Although rng-tools will work, this is not suggested since it doesn't provide real entropy. See the discussion here: https://bugs.launchpad.net/ubuntu/+source/gnupg/+bug/706011
For users that are frustrated by this, here are some things I found helpful on a server with no mouse/desktop.
1) Go through the process of creating the GPG key. If it hangs waiting for more entropy, go to the next step.
2) You can watch how much entropy your system has by opening a terminal and type (this will look at that file every second):
watch -n1 cat /proc/sys/kernel/random/entropy_avail
3) Open a third terminal to generate your entropy. You can try various things to try to boost that entropy. Here are some things that I noticed increased the entropy sufficiently to make gpg work. Note that this was somewhat random (no pun intended). Sometimes doing something would increase the entropy; but when I do it again, it does not:
Get a large file from the internet
wget http://us1.php.net/get/php-7.2.2.tar.bz2/from/this/mirror
Do something that prints a lot of stuff to the terminal:
ls -R /
sudo find /folder/with/lots/of/files/ -type f | xargs grep 'simple string that shows up in lots of files'
4) If what you are doing does not increase the entropy_avail, then try something else.