Created
July 4, 2026 02:20
-
-
Save saudiqbal/04009c310442dbfa6ba6a58749d9418f to your computer and use it in GitHub Desktop.
This Bash script generates a highly secure Ed25519 SSH key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| RD=$(echo "\033[01;31m") | |
| YW=$(echo "\033[33m") | |
| GN=$(echo "\033[1;92m") | |
| CL=$(echo "\033[m") | |
| BFR="\\r\\033[K" | |
| HOLD="${YW}+${CL}" | |
| CM="${GN}✓${CL}" | |
| CROSS="${RD}✗${CL}" | |
| msg_ok() { | |
| local msg="$1" | |
| echo -e "${BFR} ${CM} ${GN}${msg}${CL}" | |
| } | |
| msg_error() { | |
| local msg="$1" | |
| echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" | |
| } | |
| msg_info() { | |
| local msg="$1" | |
| echo -e " ${HOLD} ${YW}${msg}${CL}" | |
| } | |
| slugify() { | |
| # 1. Take input string | |
| local input="${1}" | |
| # 2. Transliterate UTF-8 characters to ASCII (e.g., 'é' becomes 'e') | |
| local slug | |
| slug=$(echo "$input" | iconv -t ascii//TRANSLIT) | |
| # 3. Replace non-alphanumeric characters with hyphens | |
| slug=$(echo "$slug" | sed -E 's/[^[:alnum:]]+/-/g') | |
| # 4. Strip leading and trailing hyphens | |
| slug=$(echo "$slug" | sed -E 's/^-+|-+$//g') | |
| # 5. Convert to lowercase | |
| #slug=$(echo "$slug" | tr '[:upper:]' '[:lower:]') | |
| echo "$slug" | |
| } | |
| echo | |
| msg_info "--------------------------------------------" | |
| msg_info "--- SSH Ed25519 Key Pair Generator Start ---" | |
| msg_info "--------------------------------------------" | |
| echo | |
| # Ed25519 key pair | |
| function Ed25519keypair() { | |
| echo | |
| echo -e "\033[0;41m Generate Ed25519 key pair \033[m" | |
| echo | |
| echo -n "Enter the name for Ed25519 key: " | |
| read keyname | |
| if [[ -n $keyname ]]; then | |
| keyname=$(slugify "$keyname") | |
| ssh-keygen -o -a 64 -t ed25519 -f id_ed25519_$keyname -C "$keyname" -N "" -q | |
| echo | |
| msg_ok "Ed25519 key pair setup done!" | |
| else | |
| msg_error "No response received!" | |
| fi | |
| sleep 1 | |
| } | |
| printf 'Generate new Ed25519 key pair [y/N]? ' | |
| read answer | |
| if [ "$answer" != "${answer#[Yy]}" ] ;then | |
| Ed25519keypair | |
| fi | |
| echo | |
| echo "---------------------------------------------------" | |
| echo "Your Ed25519 public key is:" | |
| cat "id_ed25519_${keyname}.pub" | |
| echo "---------------------------------------------------" | |
| echo | |
| msg_info "--------------------------------------------" | |
| msg_info "--- SSH Ed25519 Key Pair Generator End ----" | |
| msg_info "--------------------------------------------" | |
| echo | |
| exit 0 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now to generate a new ED25519 key pair run
bash ssh-keygen.shin your terminal