Skip to content

Instantly share code, notes, and snippets.

@stokito
Forked from hongkongkiwi/generate-dropbear-key
Last active December 14, 2023 21:34
Show Gist options
  • Save stokito/e43054c71572d77a665e2d8ec1096749 to your computer and use it in GitHub Desktop.
Save stokito/e43054c71572d77a665e2d8ec1096749 to your computer and use it in GitHub Desktop.
Generate SSH Key in Dropbear with some options (by default it uses default id_dropbear as the name and ed25519 as the type)
#!/bin/sh +ux
# Will accept key dir as first argument
KEY_DIR="${1:-"/mnt/sda1/.ssh"}"
# Will accept key type as first argument
KEY_TYPE="${2:-"rsa"}"
# Ensure the directory exists
mkdir -p "$KEY_DIR"
# Generate an RSA key using dropbear
dropbearkey -t "$KEY_TYPE" -f "${KEY_DIR}/id_rsa"
# Output Public Key
dropbearkey -y -f "${KEY_DIR}/id_rsa" | grep "^ssh-rsa " > "${KEY_DIR}/id_rsa.pub"
# Show Public Key
cat "${KEY_DIR}/id_rsa.pub"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment