Last active
July 8, 2025 21:07
-
-
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 | |
export DEBIAN_FRONTEND=noninteractive | |
### Function to create a default user | |
create_default_user() { | |
local password password_confirm password_hash | |
# Check if user exists | |
if id "kali" &>/dev/null; then | |
echo "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 | |
echo "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 | |
software-properties-common busybox xrdp lightdm | |
bash-completion task-xfce-desktop | |
) | |
sudo apt update | |
sudo apt install -y --no-install-recommends "${packages[@]}" | |
} | |
### Function to configure Kali Linux repositories | |
configure_kali_repos() { | |
# Backup existing sources.list | |
if [ -f /etc/apt/sources.list ]; then | |
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak | |
fi | |
# Write official Kali repository | |
echo "deb http://http.kali.org/kali kali-rolling main non-free contrib" | sudo tee /etc/apt/sources.list | |
echo "deb-src http://http.kali.org/kali kali-rolling main non-free contrib" | sudo tee -a /etc/apt/sources.list | |
sudo apt update | |
} | |
### Function to install Kali Linux base packages | |
install_kali_packages() { | |
sudo apt install -y libc6 | |
sudo apt dist-upgrade -y --fix-broken | |
sudo apt install -y kali-linux-default kali-desktop-core kali-desktop-xfce spice-vdagent | |
} | |
### Function to clean up | |
clean_up() { | |
sudo apt autoremove -y --purge | |
sudo apt clean | |
echo "Setup completed successfully." | |
} | |
### Main script execution | |
create_default_user | |
install_packages | |
configure_kali_repos | |
install_kali_packages | |
clean_up |
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.