How one can securely generate a new raw private key from a UNIX command line?
This private key can be then imported to wallet apps or web3.js.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
If you have openssl installed you can run
openssl rand -hex 32
Note: This will generate a 32 bytes sequence. It never verifies that the sequence is a valid private key.
There's a tiny possibility that some outputs will not generate a valid private key (a sequence of 32 zeros bytes), or a number above the elliptic curve order (FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141).
If you are really paranoid you should verify it is a valid the private key.
You can use
/dev/urandom as a safe cryptographic random number generator. The following reads 32 bytes (256 bits) from the random number generator and formats it as a single hex string.
head -c 32 /dev/urandom|xxd -ps -c 32