Background Image

Blog Post

Shell script 產生亂數密碼

Feb 08

Shell script 產生亂數密碼


使用範例 sh randpass.sh 密碼長度 密碼數量

#!/bin/bash

if [ $# -ne 2 ]; then
    echo "Usage: $0 <length> <quantity>"
    exit 1
fi

length=$1
quantity=$2

for ((i=1; i<=$quantity; i++)); do
    password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c $length)
    echo "Password $i: $password"
done

Back   
 
We're sorry. New comments are no longer being accepted.
1 person will be notified when a comment is added.
Would you like to be notified when a comment is added?
Please login or register first.