How can I generate a new random wpa/wap2 key in the linux terminal? I tried pwgen but this is not generating hexadecimal values.
Asked
Active
Viewed 5,303 times
2
-
For WPA(2) I would use all regular characters to generate from rather than just hexadecimal ones. What is your reason to generate a password from such a selected set? – gertvdijk Jan 14 '13 at 13:39
-
@gertvdijk this is required by the router – ThreeCheeseHigh Jan 14 '13 at 14:22
2 Answers
3
For instance, if you want a password with the maximum character length, i.e. 63, you can enter either of the following 2 commands:
makepasswd --chars=63openssl rand -base64 63
UPDATE:
Here is a better command I've found for this purpose since I first wrote this answer:
dd if=/dev/urandom bs=48 count=1 status=none | base64 | tr +/ -_
Actually I use this zenity-powered script to generate such a password from time to time:
#!/bin/bash
RNDPWD="$(dd if=/dev/urandom bs=48 count=1 status=none | base64 | tr +/ -_)"
echo $RNDPWD | tr -d '\n' | xclip -i -selection clipboard
zenity --question --title="Random Password" --text="<i>Password Copied to Clipboard:</i>\n\n$RNDPWD\n\n<b>Would you like to generate another one?</b>" --width=500 --height=150
if [ $? = 0 ]
then
"~/.bin/Password-Generator-GUI"
fi
Sadi
- 10,912
- 7
- 48
- 61
-
thanks for your answer, but I need to generate a 64 characters long, hexadecimal password, which is required by my router. – ThreeCheeseHigh Jan 14 '13 at 14:38
-
-
1@Sadi: "openssl rand -base64 63" generated 63 bytes of information, 84 base64 characters. – beroal Nov 06 '16 at 19:17
-
@beroal thanks for the feedback. I don't know what happened in nearly 4 years, but I've added another command - even a script - now which I hope will serve this purpose much reliably and much better ( and much longer ;-) – Sadi Nov 08 '16 at 08:54
-
-
@beroal its purpose is to replace any "+" and "/" characters (which, I don't remember now, might create problems in some cases) with "-" and "_" respectively. – Sadi Nov 23 '16 at 14:42
-
@danny Maybe you can accept this as **the answer** now - so that this good website doesn't show some many unanswered questions - although many of them are actually answered ;-) – Sadi Nov 23 '16 at 14:49
1
To generate the best possible password (with the highest entropy possible), one should use all of the ASCII printable characters - from 32 (space) to 126 (tilde, ~). This can be archieved with (for an example maximum password length of 63 characters):
< /dev/urandom tr -cd "[:print:]" | head -c 63; echo
To not include the space one can use [:graph:] character set and there are also others described in the tr's manpage.
drws
- 181
- 1
- 5