Generate random key

By | 14th October 2024

A lot of applications these days need some sort of master key to enhance security. Few simple methods to generate such a key

uuidgen method

$ uuidgen

Run this command to generate a random 32 characters long key. Most of the OS’s should have this command if not install it. More options and methods using this command can be found here.

Python method

There are many many ways in python. I stumbled upon this method for which I don’t have to install anything and run just 2 commands to get the key. The secrets method is very simple.

python3 or python
>>>import secrets
>>>secrets.tokens_urlsafe(32)
PArL_fEVainFbBSjrYjUhAgP3WpU76jGX2wz9TlV5VE

Openssl rand

Try this one-liner if openssl is available

openssl rand -base64 32

These are some of the few methods to generate a random key.