[Ethereum] How to generate a new Ethereum address and private key from a command line

private-keyweb3js

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.

Best Answer

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 private key.

Related Topic