If you need to create a random password outside of Safari or another password manager, you can use a variety of techniques. You can use the Keychain Access app, some Terminal commands, or even make your own Automator action to generate one on demand.
You can also watch this video at YouTube.
Watch more videos about related subjects: Automator (50 videos), Security (133 videos), Terminal (43 videos).
You can also watch this video at YouTube.
Watch more videos about related subjects: Automator (50 videos), Security (133 videos), Terminal (43 videos).
Video Transcript
Hi, this is Gary with MacMost.com. Today let me show you three ways to create random passwords on your Mac without using Safari.
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to MacMost.com/patreon. There you can read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
So in my recent security videos I talked about using either Safari or a third party password manager to have random passwords. Not only will a password manager allow you to store your passwords but when you signup for a new site or create a new password for an existing site you can generate random passwords to use. Random passwords are what you should be using. But what if you're not in Safari or even in a web browser when creating a password. What if you're using an app or something or in some situation where you can't generate a new password using either Safari or a password manager.
Well, there are several ways to generate truly random passwords on your Mac. The first one is to use an app that you have on your Mac called Keychain Access. This is an app that specifically deals with a keychain. What you have in Safari that stores your passwords. But we're not going to actually use any of that normal functionality. We're just going to use it to generate a new password. So I'm going to use Spotlight here to search for Keychain Access and I'm going to run it. Now you're going to see a lot of information here about all of the different items you have in Keychain. Don't worry about that. We're not using that at all. Instead we're going to go to File and then say New Password item. This will allow you to generate a new item in Keychain. But we're not going to use this either. The only reason we went here is to access this little button. Click this little key button here and it comes up with something called the Password Assistant. This will generate random passwords. It will put one there right away and you can set that type to Letters & Numbers, Numbers Only, Random, or Meeting a Certain Standard.
We'll stick with Letters & Numbers and you could change the length to be whatever you want. Then just Select again to have it regenerate a password. Then when you get what you want you could simply Copy from here and Paste it into whatever you're using or just leave this window up and go into a window in another app and type it. Of course this doesn't save your password. You're going to have to Save this. Somehow write it down. Save it in your Password Manager. But it is handy when you need to create a password and no other method is working.
Now as you might expect you can also use the Terminal to do this. I'm actually going to show you a few Commands. So launch Terminal and first let's start with a very short simple Command. This Command here will generate the date and then pipe it through an app that's going to create what's called a Checksum. Basically it's going to create a bunch of random numbers and letters that are based on the actual time right now all the way down to the second. So you can see it generates a whole bunch of different characters here. You could just take what you want. If you only want to use a certain number of characters at the beginning you can grab that. You're only going to get some letters here all the way up to f since this is a hexadecimal value. But this will do if you need something quick. Note that in Terminal you could always use the up arrow to repeat the last command and hit return. So I can keep generating passwords this way.
Here's something a little more involved. This command is actually going to use the open SSL app in Terminal and it has a random function. It's going to generate a base 64 random number and you're going to get something that looks like this. So it's going to use upper and lower case letters and numbers. This is also handy for some quick passwords.
Now here's one that's far more involved but much more useful. This long command here is actually going to use the urandom binary that's in the developer folder to create the random number. But it's going to go and assign the values to the characters that are here. So we have a to z, A to Z uppercase, zero to 9, and then dash underscore and the dollar sign. There has to be a backslash in front of the dollar sign. So if you don't want to have say the underscore and dollar sign you can remove these three characters here and you'll only get the letters, numbers, and an occasional dash. Then here is the length of the password. So we get that password there. I'll use the up arrow to generate another one. I'll use the up arrow again but this time I'll go and Edit it so it generates twelve characters. Obviously this is hard to type so you're probably going to want to Copy this and place it somewhere where you can easily access this. Put it in a Note or Text file or something so you could always just paste it into Terminal and use it.
How about using Automator to do this? After all if you can program something in the Terminal you certainly should be able to program something in Automator. Let's create something quick here. I'm going to create a Quick Action but you could do an Application as well and I'm going to add a bit of JAVAscript. So I'll put that in here and then I'll add some JAVAscript. So what this code does is it declares a variable here and it puts all of the different characters that we want to use in passwords in here. Then it starts off with a password that's blank and it's going to loop eight times. So if you want to have more than 8 characters just change the number right here. It's going to add one character at a time and it's going to grab a character at a position in here that's a random number based on the length of this string. So it's just basically going to pick eight random characters from this. Then it's going to Return. We can do something like Copy to Clipboard after that so whatever comes out of this will then go into the clipboard. So I'll have TextEdit open here and I'll run this and now when I go and Paste, Command V, you could see it pastes in an eight character password. I can run it again. Another eight character password. Now since I've created this as a Quick Action I can set everything here to work, will receive nothing in any application. I'll Save it to generate random password. Save. Now I've Quit and Restarted TextEdit and when I go into the Services Menu I can see right here Generate Random Password. I do that and now I can Paste and I get the password there. So it's kind of a handy little thing I've created. Of course, hopefully you don't need to create random passwords outside of Safari or your Password Manager that often that you need to create a Quick Action. You could always just run this inside of Automator in the odd case that you actually need a password to be created like this.
I hope you found this useful. Thanks for watching.
Here are some of the pieces of code I use in the video:
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9-_\$' | fold -w 8 | sed 1q
openssl rand -base64 6
date | md5
function run(input, parameters) { var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; var pass = ""; for (var i=0; i<8; i++) { pass += chars.charAt(Math.floor(Math.random()*chars.length)); } return pass; }
I am a long time user of 1Password, but it is not always convenient. I don't think maintaing passwords in Safari is very secure. I appreciate now knowing alternate methods of creation. Thanks!
Dale: Why do you think passwords in Safari (Keychain) isn't secure? And what is not convenient about 1Password?
I read the text version of your video hoping I would find the Terminal commands so I could cut and paste them into Terminal to try the out. I have learned the hard way that you better have the EXACT command when you use Terminal.
Would you mind providing your readers/listeners with those commands & thank you.
Bob: Posted above. Thanks.
I opened keychain access for the first time while watching this video and was surprised to see many entries in the various windows. As I have never used keychain why would this be. Great and informative video as always. Thanks Gary
David: First, are you looking at only the passwords? Keychain stores lots of other things like certificates used by websites and apps for security, etc. But if you look at just the passwords you will see anything you have stored in Safari previously as Keychain is where they are stored.