News for hackers. Stuff that matters.
Re:Random Numbers in Bash by Tepix on Monday March 27, 2023 @10:39AM (#35327246)
I use "openssl rand X" where X is the number of pseudo-random bytes i need.

Say you want to generate a strong password, you can use this handy function that works in bash and zsh:

    function gen_passwd() {
       openssl rand 240 |\
       LC_CTYPE=C tr -dc '[:graph:]' |\
       cut -c 1-${1:-20}
    }
Re:Random Numbers in Bash by Karellen on Monday March 27, 2023 @11:22AM (#35327878)
If you have a password manager installed on your system (and you should) then it might have a command-line client that can generate new passwords. e.g.:

    karellen@localhost:~$ keepassxc-cli generate -lU
    hpJUwcYZnzJyAbrnvTWnTzrlqzqcdvsl
    karellen@localhost:~$ keepassxc-cli diceware
    diabetes dinginess goldfish purr cried expenses related
See `keepassxc-cli help generate` and `keepassxc-cli help diceware` for more info, or the man page: https://manpages.debian.org/bullseye/keepassxc/keepassxc-cli...
Re:Random Numbers in Bash by zikduruqe on Monday March 27, 2023 @12:06PM (#35328418)
Or just use what you already have on your machine...

    sort -R /usr/share/dict/words | head -n 4| sed 's/.*/&/;$!s/$// ' |tr '\n' '-' |sed 's/-$/\n/'
Re:Random Numbers in Bash by r3trohack3r on Monday March 27, 2023 @12:08PM (#35328434)
Oh handy - didn’t think of using that word list. I download the EFF diceware list.
Re:Random Numbers in Bash by zikduruqe on Monday March 27, 2023 @01:18PM (#35329410)

    sort -R /usr/local/share/eff_short_wordlist_1.txt |awk '{print$2}' | head -n 4| tr '\n' '-' | sed 's/-$/\n/'
Re:Random Numbers in Bash by Karellen on Monday March 27, 2023 @01:03PM (#35329199)
Be careful with that:

> The shuf, shred, and sort commands sometimes need random data to do their work. For example, ‘sort -R’ must choose a hash function at random, and it needs random data to make this selection.

> By default these commands use an internal pseudo-random generator initialized by a small amount of entropy, but can be directed to use an external source with the --random-source=file option. An error is reported if file does not contain enough bytes.

-- https://www.gnu.org/software/coreutils/manual/html_node/Rand...

(emphasis mine)

You might end up with a fairly easy-to-brute-force password using that method.

They say "never roll your own crypto", but I think that advice probably holds pretty well for password generators(/managers). I'll stick with using a dedicated program. I reckon it's far less likely to have obvious blunders than something that's just been cobbled together using whatever tools happened to be lying around nearby.

Re:Random Numbers in Bash by r3trohack3r on Monday March 27, 2023 @12:07PM (#35328430)
Personally I have a tiny shell function that uses openssl rand with a dice ware list. It accepts a length, and it returns CamelCase.

I use it for usernames since Bitwarden doesn’t support diceware names.

Re:Random Numbers in Bash by rlpb on Monday March 27, 2023 @12:33PM (#35328776)
pwgen is great as a password generator, and is a tiny package.