Skip to content

Instantly share code, notes, and snippets.

@wshino
Forked from miguelmota/ethereum_keys.sh
Created May 17, 2023 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wshino/3aadd10c92fee1cac6cc3a6d02166937 to your computer and use it in GitHub Desktop.
Save wshino/3aadd10c92fee1cac6cc3a6d02166937 to your computer and use it in GitHub Desktop.
Generate Ethereum Private key, Public key, and Address using Bash and OpenSSL
# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > key
# Extract the public key and remove the EC prefix 0x04
cat key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub
# Extract the private key and remove the leading zero byte
cat key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
# Generate the hash and take the address part
cat pub | keccak-256sum -x -l | tr -d ' -' | tail -c 41 > address
# (Optional) import the private key to geth
geth account import priv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment