Last active
January 30, 2026 04:55
-
-
Save bluPhy/afb724fd6ba907af4d976b20eab193b7 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| export DEBIAN_FRONTEND=noninteractive | |
| export APT_LISTCHANGES_FRONTEND=none | |
| log() { | |
| printf '[%s] %s\n' "$(date '+%F %T')" "$*" | |
| } | |
| die() { | |
| echo "Error: $*" >&2 | |
| exit 1 | |
| } | |
| trap 'die "Command failed on line ${LINENO}."' ERR | |
| require_root_or_sudo() { | |
| if [ "$(id -u)" -ne 0 ]; then | |
| command -v sudo >/dev/null 2>&1 || die "sudo is required but not installed." | |
| sudo -v || die "sudo authentication failed." | |
| fi | |
| } | |
| check_os() { | |
| if [ ! -f /etc/os-release ]; then | |
| die "Unable to detect OS; /etc/os-release not found." | |
| fi | |
| # shellcheck disable=SC1091 | |
| . /etc/os-release | |
| if [[ "${ID:-}" == "kali" ]]; then | |
| die "This system already reports Kali Linux." | |
| fi | |
| if [[ "${ID:-}" != "debian" && "${ID_LIKE:-}" != *debian* ]]; then | |
| die "This script is intended for Debian-based systems only." | |
| fi | |
| } | |
| confirm_danger() { | |
| cat <<'EOF' | |
| WARNING: | |
| This script converts a Debian system to Kali Rolling. This is risky and can break your system. | |
| Make sure you have a full backup or a snapshot before continuing. | |
| EOF | |
| read -r -p "Type 'I UNDERSTAND' to continue: " confirm | |
| [ "$confirm" = "I UNDERSTAND" ] || die "Aborted by user." | |
| } | |
| apt_update() { | |
| sudo apt-get update | |
| } | |
| apt_install() { | |
| sudo apt-get install -y --no-install-recommends "$@" | |
| } | |
| ### Function to create a default user | |
| create_default_user() { | |
| local password password_confirm password_hash | |
| if id "kali" &>/dev/null; then | |
| log "User 'kali' already exists. Skipping creation." | |
| return | |
| fi | |
| while true; do | |
| read -s -r -p "Provide the password for default username (kali): " password | |
| echo | |
| read -s -r -p "Confirm the password: " password_confirm | |
| echo | |
| if [[ "$password" != "$password_confirm" ]]; then | |
| echo "Error: Passwords do not match." | |
| continue | |
| fi | |
| if [[ ${#password} -lt 8 || ! "$password" =~ [A-Z] || ! "$password" =~ [a-z] || ! "$password" =~ [0-9] ]]; then | |
| echo "Error: Password must be at least 8 characters long and contain at least one digit, one uppercase letter, and one lowercase letter." | |
| continue | |
| fi | |
| break | |
| done | |
| password_hash=$(openssl passwd -6 "$password") | |
| sudo useradd --create-home --home "/home/kali" --password "$password_hash" --shell "/bin/bash" --groups sudo kali | |
| log "User 'kali' created and added to sudo group." | |
| } | |
| ### Function to install necessary packages | |
| install_packages() { | |
| local packages=( | |
| tzdata debconf-utils keyboard-configuration | |
| libncurses5-dev libncursesw5-dev wget gnupg dirmngr ca-certificates | |
| software-properties-common busybox xrdp lightdm | |
| bash-completion task-xfce-desktop | |
| ) | |
| apt_update | |
| apt_install "${packages[@]}" | |
| } | |
| ### Function to configure Kali Linux repositories | |
| configure_kali_repos() { | |
| local sources_backup="/etc/apt/sources.list.bak.$(date '+%Y%m%d%H%M%S')" | |
| local keyring="/usr/share/keyrings/kali-archive-keyring.gpg" | |
| if [ -f /etc/apt/sources.list ]; then | |
| sudo cp /etc/apt/sources.list "$sources_backup" | |
| log "Backed up /etc/apt/sources.list to $sources_backup." | |
| fi | |
| if [ ! -f "$keyring" ]; then | |
| log "Installing Kali archive keyring." | |
| wget -q -O - https://archive.kali.org/archive-key.asc | sudo gpg --dearmor -o "$keyring" | |
| fi | |
| cat <<EOF | sudo tee /etc/apt/sources.list >/dev/null | |
| deb [signed-by=$keyring] https://http.kali.org/kali kali-rolling main non-free contrib | |
| deb-src [signed-by=$keyring] https://http.kali.org/kali kali-rolling main non-free contrib | |
| EOF | |
| apt_update | |
| } | |
| ### Function to install Kali Linux base packages | |
| install_kali_packages() { | |
| apt_install libc6 | |
| sudo apt-get dist-upgrade -y --fix-broken | |
| apt_install kali-linux-default kali-desktop-core kali-desktop-xfce spice-vdagent | |
| } | |
| ### Function to clean up | |
| clean_up() { | |
| sudo apt-get autoremove -y --purge | |
| sudo apt-get clean | |
| log "Setup completed successfully." | |
| } | |
| ### Main script execution | |
| require_root_or_sudo | |
| check_os | |
| confirm_danger | |
| create_default_user | |
| install_packages | |
| configure_kali_repos | |
| install_kali_packages | |
| clean_up |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improving user creation by using openssl to generate a random salt and the password hash, as openssl is typically preinstalled.