Hacker News new | past | comments | ask | show | jobs | submit login

My version of `pw', might be useful to those without `pwgen':

  function genpasswd() { 
    openssl rand 150 | LC_CTYPE=C tr -dc '[[:alnum:]!@#$%^&]' | tr -d iIlLOo0 | cut -c 1-${1:-12}; 
   }



Oh yeah I forgot to mention in the alias comment that it depends on pwgen. Thanks for the reminder, I just updated it.

I made a whole video on generating random password from the command line and compared a few options (including using openssl) at: https://nickjanetakis.com/blog/generate-a-random-secure-pass...

The TL;DR for not using openssl is that you're not going to get the same amount of characters every time. For example if you run yours with 48 characters instead of 12 it won't generate 48 characters every time you run it. With pwgen (something you can apt or brew install) you know what you're getting every time.


If you change `openssl rand 150` to a bigger number, say 1000 or so, you can generate longer passwords.


Ah, I see.

Did you test your solution on macOS btw? I know macOS uses an ancient version of Bash and has different binaries that act differently vs Linux (such as sed). I don't have a Mac here but I do try to make my dotfiles compatible with it. If your solution works on macOS it would be nice to drop the pwgen dependency.


I use it on macOS and it works fine. There is a brew recipe for pwgen, but that's one more dependency to worry about.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: