command line password generator from the whm/cpanel UI

Operating System & Version
AlmaLinux v8.7.0
cPanel & WHM Version
cPanel & WHM v108.0.13

infugia

Registered
Mar 1, 2023
1
1
3
Plano, Texas
cPanel Access Level
Root Administrator
Inside the cPanel/WHM interface, you are able to use passwords that are generated by the cPanel/WHM interface. Is there something that I can run in the command line to generate a password using the same system/generator as this UI in the cPanel/WHM interface?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
17,470
2,843
363
cPanel Access Level
Root Administrator
Hey there! I'm not currently finding a way to do this on my end, so it doesn't look like we have a tool readily-available to perform this work. This would be an excellent feature request if you'd like to submit one using the link in my signature, and I can bring it up with the team during our meeting next week.
 
Jan 16, 2023
13
3
3
Clovis, NM, USA
cPanel Access Level
DataCenter Provider
If you want to generate random passwords in the clear you can do this in Python. Just change the range value. Reference: Python Documentation

Python:
import string
import secrets
alphabet = string.ascii_letters + string.digits + string.punctuation
password = ''.join(secrets.choice(alphabet) for i in range(12))
print(password)
If you want to generate a password that is hashed for adding to scripts you can use the following from the cli.

Python:
python3 -c "import crypt, getpass; print(crypt.crypt(getpass.getpass(), crypt.METHOD_SHA512))"
Use xkcdpass to get memoizable passwords. You can run it directly from the command line or add it as a Python module. Reference: martinheinz.dev.

Python:
# pip install xkcdpass
from xkcdpass import xkcd_password as xp

word_file = xp.locate_wordfile()
words = xp.generate_wordlist(wordfile=word_file, min_length=5, max_length=10)

for i in range(4):
    print(xp.generate_xkcdpassword(words, acrostic="python", numwords=6, delimiter="*"))
You can also use openssl. Change 12 in cut-c1-12 to the length you want. You will also need to change the number behind base64 to be a few more bytes above the desired password length. Reference: Red Lever Solutions

Bash:
openssl rand -base64 16 | tr -d "=+/" | cut -c1-12
Or save in a file and drop it in your /usr/local/bin and make sure that is in your path so you can run it anywhere from the system. (make sure to chmod +x filename to make it executable).

Bash:
#!/bin/bash

LENGTH=25
if [ ! -z "$1" ] && [ $1 -gt 1 ]; then
  LENGTH=$1
fi
NUMBYTES=`echo $LENGTH | awk '{print int($1*1.16)+1}'`

openssl rand -base64 $NUMBYTES | tr -d "=+/" | cut -c1-$LENGTH