generate strong pre shared key in linux

How to Generate Strong Pre Shared Key in Linux

Pre-Shared Key (PSK) is a shared string of characters used for authentication in cryptographic processes. It is also known as shared secret. As the name implies, it is shared between two parties who need to authenticate each other, before authentication takes place. It is commonly used in VPN connections, wireless networks using WPA-PSK (Wifi Protected Access Pre Shared Key) & WPA-PSK2, and many other authentication mechanisms. There are several ways to generate strong pre shared key in Linux.


How to Generate Strong Pre Shared Key in Linux

Here are the different ways to generate strong pre shared key in Linux.

1. Using OpenSSL

OpenSSL is a popular tool used for various cryptographic functions including key generation. You can generate strong PSK using its rand sub command. We will pass its output through base64 encodings.

$ openssl rand -base64 32
$ openssl rand -base64 64

2. Using GPG Command

GPG is a command line tool that provides encryption and signing services using OpenPGP standard. You can use its –gen-random option to generate strong PSK key and filter it through base64 encoding. Here is an example command.

$ gpg --gen-random 1 10 | base64
$ gpg --gen-random 2 20 | base64

In the above command, 1 and 2 are quality levels while 10 and 20 are character counts.

3. Using date and sha256sum commands

You can also use a combination of date and sha256sum commands to generate strong PSK.

$ date | sha256sum | base64 | head -c 45; echo

In the above command we pass the current datetime value to sha256sum. We pass its output to base64 encoding and finally use head command to extract the first 45 bytes of output. You can vary its length as per your requirement.

4. Use Pseudorandom Number Generators

You can also use pseudorandom number generators such as /dev/random or /dev/urandom to generate a random numeric string. We call head command to extract the first few characters from the randomly generated string. We pass its output to base64 encoding to get final PSK. Here is an example to generate a pseudorandom number and extract the first 35 characters from its output. This output is passed through base64 encoding to obtain PSK string.

$ head -c 35 /dev/random | base64

In this article, we have learnt how to generate Pre Shared Key in Linux.

Also read:

How to Run Command After Certain Time in Linux
Timeout Command in Linux
How to Set SSH Warning Message in Linux
How to Remove Specific Item from JS Array
Detect Mobile Device in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *