PSK/ Pre-shared key is a random string password composed of encrypted and confidential data. It is mainly used for both parties in the encryption process to know the key, because both encryption and decryption processes require the key. The pre-shared key can prevent other people from obtaining important data through the network and improve network data security. Using PSK when sharing data also ensures that the data is only accessible to the people the user wants to share it with. Below is an example and command sharing on generating PSK keys on Ubuntu Linux.
If a user needs to use the date command in Linux to view information about the date and time of the system, the following command can be used to generate a strong key. Use date, sha256sum and base together to obtain the random key, and then use the random key for PSK encryption data:
[email protected]:~$ date | sha256sum | base64 | head -c 15; echo [email protected]:~$ date | sha256sum | base64 | head -c 25; echo [email protected]:~$ date | sha256sum | base64 | head -c 35; echo
The commands provided above generate and output a pre-shared key (PSK) of 15, 25, and 35 bytes in length. The purpose of the head command is to capture these bytes and display them in the output. If you do not use the head command, the system outputs a PSK string with a length of 92 bytes.
The /dev/random and /dev/urandom files in Linux contain several random number generators, which are special files that act as random number generators in Linu. Both /dev/random and /dev/urandom create random numbers using the Linux entropy pool, which collects noise from the environment, such as CPU fans, mouse movements, and so on. The noise in the entropy pool is then used by these files. These random integer pass base64 command combinations generate strong character combinations suitable for pre-shared keys (The head command the -c option used in character form is used to generate keys.) :
[email protected]:~$ head -c 20 /dev/random | base64 [email protected]:~$ head -c 30 /dev/random | base64
OpenSSL is used for shell access to the OpenSSL encryption library. Construct a strong PSK with the rand subcommand, which generates pseudo-random bytes and filters them through base64 encoding, such as generating pre-shared keys 32, 64, and 128 bytes long:
[email protected]:~$ openssl rand -base64 32 [email protected]:~$ openssl rand -base64 64 [email protected]:~$ openssl rand -base64 128
In Linux systems, GNU Privacy Guard (GPG) is not only a widely known tool for encrypting and decrypting files, but can also be used to generate powerful pre-shared keys (PSKS). By using the --gen-random method of the gpg command combined with Base64 encoding, characters of any length can be generated as pre-shared keys.
In the following commands, 1 represents the quality level of the random number, while 10, 20, 32, 64, and 128 represent the number of bytes generated.
[email protected]:~$ gpg - - gen-random 1 10 | base64 [email protected]:~$ gpg - - gen-random 1 20 | base64 [email protected]:~$ gpg - - gen-random 1 32 | base64 [email protected]:~$ gpg - - gen-random 1 64 | base64 [email protected]:~$ gpg - - gen-random 1 128 | base64