Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Generate a Random Secure Password on the Command Line with pwgen


In this video, we'll go over how to generate a password of custom length with at least 1 uppercase / special char and 1 number.

Quick Jump: Demo Video of Using the pwgen Tool

I have over 300 passwords saved in the pass command line tool and I recently started generating random passwords for them. I’m finding this to be a lot faster than manually coming up with long word based passwords.

Demo Video of Using the pwgen Tool


pwgen -sync 48 -1

I’ve also set up a pw alias to quickly generate passwords and copy them to your clipboard.


  • 0:22 – Running the pwgen command without arguments
  • 0:47 – Generating a password with a custom length
  • 1:34 – Ensuring passwords have at least 1 uppercase char / special char / number
  • 3:45 – Generating a few passwords to see how it works
  • 4:27 – Creating a custom alias to make it easier to generate passwords
  • 4:47 – Using the pw alias to generate passwords and copy it to your clipboard
  • 5:21 – A common work flow of generating a pw and using it
  • 6:18 – Why I don’t use tools like openssl to generate passwords

What tool do you use to generate random passwords? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.