背景
在搭建Ubuntu16.04的本地apt源時,需要運行“gpg --gen-key”命令,但是在執行該命令時,出現了:“Not enough random bytes available. Please do some other work to give the OS a chance to collect more ”的提示,而且一直卡住。
分析
更詳細的提示,參加:
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
根據提示,該命令生成key時,需要kernel為該程序生成足夠多的隨機數,因此,我們只需要為kernel生成隨機數即可。
解決方法:
安裝rng-tools工具,該工具可以像指定文件生成隨機數。這里,我們不需要退出原正在執行gpg --gen-key命令的console,新建一個終端,執行如下命令。命令執行完成后,原來卡住的界面就恢復運行了。
$ apt-get install rng-tools
$ rng -r /dev/urandom