4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (2024)

Aaron Kili Read Time: 1 minCategories Linux Commands 5 Comments

A Pre-Shared Key (PSK) or also known as a shared secret is a string of characters that is used as an authentication key in cryptographic processes. A PSK is shared before being used and is held by both parties to the communication to authenticate each other, usually before other authentication methods such as usernames and passwords are applied.

It is commonly used in different types of Virtual Private Network (VPN) connections, wireless networks in a type of encryption known as WPA-PSK (Wi-Fi Protected Access Pre-Shared Key) and WPA2-PSK, and also in the EAP (Extensible Authentication Protocol Pre-Shared Key), and many others authentication mechanisms.

In this article, we will show you different ways to generate a strong Pre-Shared Key in Linux distributions.

1. Using OpenSSL Command

OpenSSL is a well-known and widely-used command-line tool used to invoke the various cryptography functions of OpenSSL’s crypto library from the shell. To generate a strong PSK use its rand sub-command which generates pseudo-random bytes and filter it through base64 encodings as shown.

$ openssl rand -base64 32$ openssl rand -base64 64
4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (1)

2. Using GPG Command

GPG is a command-line tool to provide digital encryption and signing services using the OpenPGP standard. You can use its --gen-random option to generate a strong PSK and filter it through base64 encoding as shown.

In the following commands, 1 or 2 is the quality level and 10, 20, 40, and 70 are the character counts.

$ gpg --gen-random 1 10 | base64$ gpg --gen-random 2 20 | base64$ gpg --gen-random 1 40 | base64$ gpg --gen-random 2 70 | base64
4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (2)

3. Using Pseudorandom Number Generators

You can also use any of the pseudorandom number generators in Linux such as /dev/random or /dev/urandom, as follows. The -c option of the head command helps to generate the number of characters.

$ head -c 35 /dev/random | base64$ head -c 60 /dev/random | base64
4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (3)

4. Using date and sha256sum Commands

The date and sha256sum command can be combined to create a strong PSK as follows.

$ date | sha256sum | base64 | head -c 45; echo$ date | sha256sum | base64 | head -c 50; echo$ date | sha256sum | base64 | head -c 60; echo
4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (4)

The above are some of the many ways of generating strong Pre-Shared Key in Linux. Do you know of any other methods? If yes, share it with us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (5)

Next article:

How to Install LAMP Server on CentOS 8

4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (6)

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)

Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Related Posts

How to Transfer Files (Local and Remote) in Linux

How to Sync New and Changed Files Using ‘rsync’ Command

How to Search Files by Name or Extension Using find Command

10 Lesser Known Linux Commands – Part 2

11 Lesser Known Useful Linux Commands

26 Security Hardening Tips for Modern Linux Servers

5 Comments

Leave a Reply

  1. My favorite, because you can choose which characters are used:

    < /dev/urandom tr -dc a-zA-Z0-9 | head -c64

    This will create a 64 character alphanumeric PSK.

    Replace a-zA-Z0-9 with another list of characters and ranges to control which characters occur, and replace 64 with another number to control length.

    e.g.

    8 lower-case letters

    < /dev/urandom tr -dc a-z | head -c8

    16 handwriting-unambiguous alphanumeric characters

    < /dev/urandom tr -dc a-jmnoqrtyA-HJLMNQRTY2-9 | head -c16

    64 alphanumeric characters and all non-space printable ascii symbols (\ escapes the ! for the shell)

    < /dev/urandom tr -dc \!-~ | head -c64

    64 URL-safe characters (\ escapes the ()'!*; for the shell)

    < /dev/urandom tr -dc a-zA-Z0-9-._~\(\)\'\!\*:@,\; | head -c64

    Reply

    • @Carlo,

      Thanks for the tip, hope these commands helpful to our readers…

      Reply

  2. Note that using “date” to generate keys is *not* secure.

    date prints strings like “Sun Dec 6 18:05:53 PST 2020”. Since this string changes once per second, in any given day there are only 86,400 potential keys. This is a tiny number of keys that is easy for an attacker to brute force. In comparison “openssl rand -base64 32” has 256^32 potential keys, a vastly larger number that is difficult to brute force (115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936)

    Reply

  3. “4. Using date and sha245sum Commands”
    should read:
    “4. Using date and sha256sum Commands”

    It’s confusing enough without hurting the noob’s brain even more! ;-)

    Thank-you.

    Reply

    • @Nooby,

      Thanks, corrected the command in the article.

      Reply

Got Something to Say? Join the Discussion...

4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux (2024)

FAQs

4 Ways to Generate a Strong Pre-Shared Key (PSK) in Linux? ›

Generate a PSK by using /dev/urandom

On a Linux or macOS operating system, use /dev/urandom as a pseudorandom source to generate a pre-shared key. In the Linux or macOS command-line interface, run the following command to send the random input to base64 : See more code actions.

How to generate psk in Linux? ›

Generate a PSK by using /dev/urandom

On a Linux or macOS operating system, use /dev/urandom as a pseudorandom source to generate a pre-shared key. In the Linux or macOS command-line interface, run the following command to send the random input to base64 : See more code actions.

How to get a pre-shared key? ›

Check the Keychain (Applications > Utilities > Keychain Access). The Pre-Shared Key is usually saved here. Enter "Shared Secret" into the search bar to view a list of all your saved PSKs.

What command may be used generate strong user passwords in Linux? ›

Apg (stands for Automatic Password Generator) is a command line utility for generating strong random passwords. A good thing is Apg will generate "pronounceable" passwords. They are referred to as "pronounceable" because the passwords may actually be pronounced like regular words.

How to generate a key in Linux? ›

Procedure
  1. In a terminal, run the ssh-keygen command.
  2. Generate the public/private RSA key pair.
  3. Specify the directory in which to save the key pair. For example, /Users/mymac/. ssh/id_rsa... mysftpkey.
  4. Enter the passphrase. Then, enter the same passphrase again. Enter empty if you don't want to use a passphrase.

How to generate PGP key pair in Linux? ›

Generate A Key Pair
  1. Open a command shell or DOS prompt.
  2. On the command line, enter: pgp --gen-key [user ID] --key-type [key type] --bits [bits #] --passphrase [passphrase] ...
  3. Press "Enter" when the command is complete. ...
  4. PGP Command line will now generate your keypair. ...
  5. To display your new keypair enter the following command:
Jan 31, 2024

How do I create a PSK signal? ›

To generate a PSK Modulation using the front panel:
  1. Press the TOP menu button.
  2. Press the Waveform button.
  3. Press the Modulated button.
  4. Press the Modulation Type menu button. ...
  5. Select the (n)PSK modulation type from the list box using the arrow keys, and press ENTER.
  6. Press the PSK Type menu button.

How to create a shared secret key? ›

Procedure
  1. In the search field, enter shared .
  2. From the search results, click Shared secret key.
  3. Click Add.
  4. In the Name field, enter the name for the configuration.
  5. Set the administrative state of the configuration.
  6. From the File name list, select the file that contains the key material.

How to generate a secret key? ›

There are two ways for generating a secret key in Java: generating from a random number or deriving from a given password. In the first approach, the secret key is generated from a Cryptographically Secure (Pseudo-)Random Number Generator like the SecureRandom class.

What are the types of pre-shared key? ›

Pre-shared key encryption (symmetric) uses algorithms like Twofish, AES, or Blowfish, to create keys—AES currently being the most popular. All of these encryption algorithms fall into two types: stream ciphers and block ciphers.

How to find PSK key? ›

Where do I find my WEP key or WPA/WPA2 preshared key/passphrase?
  1. Contact your system support person. The person who set up your network usually keeps the WEP key or WPA/WPA2 preshared key/passphrase. ...
  2. See the documentation that came with your access point (wireless router). ...
  3. View the security settings on the access point.

How does PSK work? ›

Phase-shift keying (PSK) is a digital modulation process which conveys data by changing (modulating) the phase of a constant frequency carrier wave. The modulation is accomplished by varying the sine and cosine inputs at a precise time. It is widely used for wireless LANs, RFID and Bluetooth communication.

How to generate passwords in Linux? ›

makepasswd command generates true random passwords by using the /dev/random feature of Linux, with the emphasis on security over pronounceability. It can also encrypt plaintext passwords given on the command line. The updated version of generate new password, optionally apply it to a user.

Which Linux command allows you to run a command as more powerful user? ›

The sudo command allows you to run programs with the security privileges of another user (by default, as the superuser).

How to implement a strong password policy in Linux? ›

Table of Contents
  1. Set up password requirements on a Linux host. Set the minimum password length to 12 characters: ...
  2. Configure the account lockout settings on a Linux host. Configure accounts to lock out after 3 failed logins and remain locked out for 10 minutes. ...
  3. Create a temporary user account.

How to generate host key in Linux? ›

5.2 Create a New Host Key
  1. Log in as root.
  2. Terminate any instances of sshd using the server script. ...
  3. Use ssh-keygen to generate a new host key. ...
  4. (Optional) If you use a new host key name and/or location, edit the server configuration file (/etc/ssh2/sshd2_config). ...
  5. Restart the service.

How to generate secret key in Linux? ›

In Linux, there are several ways to generate a strong PSK, and in this article, we will discuss four of them.
  1. Use Random Characters. ...
  2. Use Passphrases. ...
  3. Use Hash Functions. ...
  4. Use Hardware Security Modules (HSMs) ...
  5. Using a Password Manager. ...
  6. Using Hardware Security Modules (HSMs) ...
  7. Conclusion.
Mar 31, 2023

How to generate encryption key in Linux? ›

On the command line, type:
  1. For 128-bit key: openssl enc -aes-128-cbc -k secret -P -md sha1.
  2. For 192-bit key: openssl enc -aes-192-cbc -k secret -P -md sha1.
  3. For 256-bit key: openssl enc -aes-256-cbc -k secret -P -md sha1. “secret” is a passphrase for generating the key. The output from the command is similar to:
May 10, 2024

Top Articles
Data Science and Blockchain Technology
Inclusive instant payment system Higala launches in the Philippines - FinTech Futures: Fintech news
Truist Bank Near Here
Methstreams Boxing Stream
7 Verification of Employment Letter Templates - HR University
Gomoviesmalayalam
Mountain Dew Bennington Pontoon
Gabriel Kuhn Y Daniel Perry Video
Evil Dead Rise Showtimes Near Massena Movieplex
Ati Capstone Orientation Video Quiz
Heska Ulite
Tugboat Information
Seth Juszkiewicz Obituary
Clairememory Scam
Aita Autism
Craigslist Labor Gigs Albuquerque
World Cup Soccer Wiki
1Win - инновационное онлайн-казино и букмекерская контора
Mephisto Summoners War
Pvschools Infinite Campus
ocala cars & trucks - by owner - craigslist
Non Sequitur
2016 Ford Fusion Belt Diagram
Cvb Location Code Lookup
Dr. med. Uta Krieg-Oehme - Lesen Sie Erfahrungsberichte und vereinbaren Sie einen Termin
Salem Oregon Costco Gas Prices
Voy Boards Miss America
Amazing deals for DKoldies on Goodshop!
Dwc Qme Database
Reborn Rich Kissasian
Employee Health Upmc
SN100C, An Australia Trademark of Nihon Superior Co., Ltd.. Application Number: 2480607 :: Trademark Elite Trademarks
Craigslist Illinois Springfield
Blackboard Login Pjc
Copper Pint Chaska
The Goonies Showtimes Near Marcus Rosemount Cinema
How to Use Craigslist (with Pictures) - wikiHow
Parent Management Training (PMT) Worksheet | HappierTHERAPY
Restaurants Near Calvary Cemetery
Srg Senior Living Yardi Elearning Login
Babylon 2022 Showtimes Near Cinemark Downey And Xd
Property Skipper Bermuda
The best specialist spirits store | Spirituosengalerie Stuttgart
Sdn Fertitta 2024
Trivago Anaheim California
Union Supply Direct Wisconsin
Understanding & Applying Carroll's Pyramid of Corporate Social Responsibility
Wild Fork Foods Login
Round Yellow Adderall
Att Corporate Store Location
Bloons Tower Defense 1 Unblocked
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5563

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.