Generate Random Password in Linux and Solaris CLI (pwgen)

According to pwgen man page, “the pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible.” It returns multiple password options that meet the criteria you provide so that you can select the one that you prefer.

### Install pwgen

On RHEL/CentOS Linux, you can install pwgen using your package manager

[root@testos]# yum install pwgen
### Generate passwords with pwgen:

Run pwgen with no options will simply spit out 160 passwords with 8 characters each:

[root@testos]# pwgen
foh9Choo AeleeD9P Xu0phaho ieteuk8A Aegh8eil Quee8eec Iuph1jee Aitai9ch
noo3eiJe zah6Ahsh Aeg4vequ ibee9Buu uu8Phaim ieJ2Gie1 Uu5Aesha ooph5coB
yieV8the Ii2theez Mie5zaeb Utoo1oos beegah4O woThie2A ohShohd6 aaF9Ahph
ebei8ieB AhChi5Sh ein9ahGh ohth7ooG aiC5fei4 Aitoo0ie Ohghei2A Doh3ooYa
Rohnai1l HohzooB1 nai2Pioc Lea1aef6 eiB7Eez1 Yoo2Eeru fiePh2Ne JaeWo3ae
zooDo0xa wie6OoLa phee5Tha iesh7ohT Cin5aif6 Aeyahri3 ya3Foa9e Eiw4Uzin
Aes3bahd matu2UiD is7IePex Chai4eiM yahquo9T oloex1Zi oovi4Mu2 Iet9ughi
Yo3quah4 thai6iPh ma0ieHoh ouCh8eim iwaG6noo quar1giL Shai7Aex Cipie6ee
Adeig4ah aes8Eeph uozaaTh2 mah4sohG Xu4feegh NoXa1eip KuL4eeTi jo9fohK6
cae8ohRo sah4ahCh Jai8Ea5U eeS3viet Kuuxu5no eiP4aeni Chei2mab Shoh3aiw
nae2zeiR Jua7Iqu9 iepho4Ie ahb9aeHi siegho6B pa7AiShe thu5eiPh ieng1Oo0
oz6piGal lii3Fe8e tique7Ru Ailiw8ch eel4Eek1 EechoT2A Re9ohthi xae0Shoo
Ivoo7Nei Achaex5i aeMo5hee fat5Esah aen3ohGo Dahth6ku uKoh7LiT Aishoag1
phaiZoh0 ChiH0chu ahx7eiTh ooFee2ch ufei2eeS Ai5ma4ah ke0theiX Zihe8vah
eu3GaJoo xae0ahMi AhSh5ic3 nahDo3ao dooka3Oh ien1Mahh Fo0ijohs ZohB2phi
pooweP8i aewohPh4 Ieze6ath eiSub2oo Auphah8P teiQu9ee io9gaiKe uBix7Eik
uc6Eiph9 Hoo5Iepu eeHa3pee ahquiSh1 exie3euX ahxiCh2i Noof0kei Ooqu6AiH
agahgh4A OhNg9ap8 deiGu1Ge arahG2oo ohSaeh5i Eesh6ouM To8Adohx eeghi6Ko
Ual5beif phaeD8ow Ih3uwah4 ieG8thac aToh2pie Mai2pee3 iuk8ooZ9 Ael3eeli
tufie3Ph OosaeX0h ta3nae9G DisakeY8 ooH9iu0C Quook0ex vohj4Auk xeiKi5ae

If you need a secure password of a specific length, run pwgen –secure (or -s) followed by the character length you need:

[root@testos]# pwgen -s 20
jjQ3qStqSvSzX9XrcXg5 QmXVeOfMhmhoZ6ybaaRC 2eq1MSJ8gdI5ME8XA41O
bKVAtXsWV6VFZ5Sp9n48 qOOnNznDEJEpe7q3FmWv S0TGnY1PZEJ0GRdz5nHA
mKiYhZpys5LWfowSQcPq RTzsppgD0HgMQGMwMb6i WxyikYRbd6fQPdjDFcT7
SSltfGWA3t4sDYsGaLNr cm0sGQvitj4bNeytsxCp MEfD1Ayph6feNCMi1GNt
zgAF0v8zdk8YR3TTmfF0 xfHItYIQ7fpVALJFcFC3 SnLsbUbDck1uxXhX9HA8
fqLpjkr5IUpTd36S4HJC qyCWw2kuXHB9DkmIaRoX ZtQBjL7BYxKvr6opTy70
0QtF0xe6piUgAsym11hv hu7IbupsyXVJOsU7wHdK qaLYSNufI56QcgiA4SOn
HuaLk3Il4Z5DoLhp95O9 ietZWSK7AQ2x0m6ADCJA P7MBoc0eThUo7S2nIS5c
Mr09BX7HZPr4EoMIJFvC 9MZJ0eMHC0dm72f1zpA2 q2VvnGOSbUogMKo0LKkW
ex94PXrFFHLBVqbR95J9 rJOONCP8p8NjSXuCPi2I NskAVR3Twa03TxLcnHYc
Gs2wrutzoorfi19GrOvy 3chCHirHBKtk9PCkOg7n bsiZ2Zw3w7BXHgMDdlfu
5Y02stv96zzYA1s2b5Kp HhVg4UrBlRQqoytR8vpj z5XHflVbVpGzw2mb8VQN
6zGqnlwIaJWvhuLHfz7d XLfIhNR9w3xxmTLVEy3n KoApskh3bjjN72nO1GHR
hIqHCQ9m3e1xvwhLi10n ueVF4DmiRm2erVgGCPAY LEwx6oljwpCG89i5NpAw
7qFFQM4Aly2QD2kvZhEl 5DZ4ZB57EAfPr2XnPVm0 JW94aTdF3INkPpqhDLfT
yUXJlKZtqGnhaJBNP9oW DXlv8xMT5QEh6IoJjP7e uncskhzm6FQpKB6cEGQf
dKpBw788fSZU84dq3MY1 Uge0moFV41uDyrdD0N4O KfyzDZbzjhX5Fil9KTDy
0gSIu5VwFI9f87zeQ7TJ dO6nM0T2xLFtvCYVsWs7 rYCZF1rZmjyltqSYOxaV
MLpdADZ9NISCTaTAw31J 6RBhNL3yRpCZQC3mhfuc jZpB7iFZs3fYFGTV7a6D
P8NsthjdZNTAgnI5TifX NRD1AGkZ3wNLoYSW8mXI ec6jiK5X0dk1qjfd8TRP

Run pwgen –symbols (or -y) followed by the desired character length to generate a password that has special characters:

[root@testos]# pwgen -y 20
iec0no0Kae7iebox`iux ai5Ievi)wiiw~oo2thie thai"xu9uphei5ahw1Oo
Ig1aa7iu9au5Phae!ph3 Baiza*ogh'oox6feeRai biCh7ii5eiV8shaeM|ah
oeS2aij6Iaph8oop^ied eini9lae3voo]suSh{ai eec3Neez)eiGoo/neefa
Meijuh8uur~ush0lahcu ooQu]e5Ing=aimai3thi ahwie|lieth3ve1dahX6
ahY"aezae$ki2jiethoh ogu2viePohC>u~m5powe urah2aiXo%uc5ahcho5O
Atoo\moh!pheem8aiyie uu`cha5shei1xaeP7ohd paQuaich6eg6ijoonie%
hi7shiCh@euQu9Vieghe aa8aewoh*The2bi3OChi wa0AiQu!ohwukoh`Tad;
toh0Aibataa&y3ogahng xohNg0lai^b&oh5hoh1i eiQuai5Aixahcei1Hi@l
jeephi7iechaes_a4Mie UiDae3sha@Yahghaicew uiZ0aV1iJ1iM\a8ie9iB
Shiiweh;ei#b8eid7Eiw eigh'ie&toojooJool2w ieLie+ng2ceeZuech%ie
ohthe-i4iGah3wuz0jae ieF9vei)rua1eeyeu<gh ce0aeX%eeVoch2AeDoju
Iep2ieBeef3ao9iekoo> muk5vaab#ai>ghooY4To Een2al"eiNge&tae3yo*
eingo4IegoeK.e6hu9ai rei0Cha|ngong0chech1 Uje*Qu5seeko>vo3ciph
ac3Chohh0aetoog6pho/ Iona0sho,h7goPhie5ee chob0jeeTh=oh=Ng1thi
iHee]po3ka7aoquai@qu ungaeb3bae<k%ei=ko1P mei1Ap9uo~R:ahGh1jui
ku'Ph+a4ahm0zoosh>ai oof5Nunueng0xi!ah*ai ahJ0siem;e7seeD9oozu
ji1AiWu3Yie9aihahng& Ahcae7einei*v7sheoth coF8chahNgee/ph~aiFo
eeth=a2phiem5Aezeir8 Ohziwee5io+p*aic1Ore Aix=iemee|toM2Osh3ae
xoiX4Roh2ieshiv@ee4i og8io?s@ieJohNg'u1Oo Iojaiceosh<eeg4Lu3da
quoovohshooM$ieR^e9j Fi8ahk1kiphie%pu7esi shah4johngu8ahkue?F3

Run pwgen –capitalize (or -c) followed by the character length to generate a password with at least one capital letter:

[root@testos]# pwgen -c 20
meghahNg1Lae5queet9o itesh2cah6etiNg3aeTa cee1soove8IM6ibainge
aewohqu8eiz7Ooghiej8 aphah4ZeiphohT4kojiL Ahzooze1eisei8Achaag
mi1phaePoShae7phes3U ied8fei6iDagh3pu0foc Wa9iwu2veew5Oht9ilah
leocooD4choeNg8uagou eishe9ri5eeM5aupheic ice3ne0Aax7daiwai3Ku
ahleeth2quethee5buTh eosh6re9AeHoquaisahj hie6EiYoh7Caithuase4
du4MeijooShaiweidohg ma5Xaibi5Sho2ieCe1Ie uCho9ugooTiePa3ungua
ahn4ahyuY5Maif5eon0U aeP0aecaeVepaek9ueth oopahn3Wae0oosh3aeNg
at4thaayah3poo0Oobee ethe8HuuH6lu9Vievupo ahghi4nieCohphee0eez
ethi6Wuxiegee4IeCh8w Nu7hephajoonee9iefei eeyavohgae2Eivei5xoh
oonga6ahphaiF6ohp4oo cheiquoo9et4Ooph4bi9 vueMazaiT9caebohJash
Phai5lozahxaedeipeiy ne4reeCungateichang9 ifideelie3xuRiu4eeth
Ahteiz0we6jouy1aet1c AeMiePieCooreiw4eixa bo6vieno8ais1eiV2gae
bum9aeshoofo9xo6Shat ohh1Eo2Weo2voocoo4ae Noo0bohk6ienaid9seez
thahZiezoh2ieng8xaiB ahz9iew3bohch4baChie aeCahk7Vee9Nooch6eit
aithaeH4Iisohmi4zei2 itha0chathi0Eeh0Eem8 hiShee5boe3ailieWung
phize2uga7eeh4Piequo ooquuvaichooc9Aeh2ie ohHun3jahDahChah4Phu
boo5aongai8zahfohQu7 aicuy8eing1ye4Moophu Ohgh8pohn0Di0Zeih7be
ooZ1eegao3Eepies2EeM chai7quaG1fengeefuza Ohg7aetoh5aeM3zoh5ne
ahquooYophie2eequ8Xa siebooPaelohph8thiyu oota1Ii2iwahN5Ahshah
pheeGaifei1quaezisha ohpaiphuGeiF1ye6taiZ tou5Aengiebangashei4

Run following pwgen command will generate a column of 5 random secure passwords with 20 characters each and at least one special character:

[root@testos]#  pwgen -sy 20 5 -1
*(Cn4+6;o4'h!}g4;qpu
\*%~o[6r}s+zZ.;h-EXN
39fzu1!:Z$[~KX}'\T<2
w@:AGaDLc~VD2m.>+<HG
s=:]?V~w&f1bfBNq_yio

Leave a Comment