From 21515daef1a3e1fb2612e55032f1d59eaf487845 Mon Sep 17 00:00:00 2001 From: elAgala Date: Thu, 23 Jan 2025 23:47:10 -0300 Subject: [PATCH] Fixes - Fix prometheus files path - Fix sciprt allowing to execute w/out username param - Add oh-my-zsh installation - Fix typo un ssh authorized_keys file - Fix PermitRootLogin disabling --- README.md | 16 +++++++++++++++- index.sh | 5 +++++ monitoring/install_prometehus.sh | 2 +- user/ssh_config.sh | 8 ++++---- utils/install_zsh.sh | 9 +++++++-- web/setup_ufw.sh | 3 ++- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a076a6a..73e36e3 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -# server-initializer \ No newline at end of file +# server-initializer + +## Installation + +```bash +wget https://raw.githubusercontent.com/elAgala/server-initializer/main/index.sh +chmod +x index.sh +./index.sh +``` + +## Included +- Server update +- User creation +- SSH key configuration (AllowUser, disable root login) +- diff --git a/index.sh b/index.sh index e91ae69..325a255 100644 --- a/index.sh +++ b/index.sh @@ -3,6 +3,11 @@ REPO_URL="https://github.com/elAgala/server-initializer" TARGET_DIR="/tmp/server-initializer" +if [ -z "$1" ]; then + echo "[ ERROR ]: No username provided. Use ./index.sh " + exit 1 +fi + if [ ! -d "$TARGET_DIR" ]; then echo "Cloning the repository..." git clone "$REPO_URL" "$TARGET_DIR" diff --git a/monitoring/install_prometehus.sh b/monitoring/install_prometehus.sh index f67710e..710d4ed 100644 --- a/monitoring/install_prometehus.sh +++ b/monitoring/install_prometehus.sh @@ -1,7 +1,7 @@ #!/bin/bash function install_prometehus() { - REPO_URL="https://raw.githubusercontent.com/elAgala/monitoring-template/main" + REPO_URL="https://raw.githubusercontent.com/elAgala/monitoring-template/master" username="$1" monitoring_dir="/home/$username/monitoring" diff --git a/user/ssh_config.sh b/user/ssh_config.sh index a92ad6a..99a099e 100644 --- a/user/ssh_config.sh +++ b/user/ssh_config.sh @@ -9,10 +9,10 @@ function config_ssh() { sudo mkdir -p $ssh_dir sudo chmod 700 $ssh_dir - sudo touch "$ssh_dir/authorized_leys" - sudo chmod 600 "$ssh_dir/authorized_leys" + sudo touch "$ssh_dir/authorized_keys" + sudo chmod 600 "$ssh_dir/authorized_keys" sudo chown -R "$username:$username" $ssh_dir - echo "[ SSH ]: Created ~/.ssh/authorized_leys" + echo "[ SSH ]: Created ~/.ssh/authorized_keys" echo "[ SSH ]: Paste the public key for $username (leave empty to skip)" read -r public_key @@ -24,7 +24,7 @@ function config_ssh() { fi echo "[ SSH ]: Disabling root login" - sudo sed -i 's/^#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config + sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config echo "[ SSH ]: Root login disabled" echo "[ SSH ]: Adding $username to allowed users" diff --git a/utils/install_zsh.sh b/utils/install_zsh.sh index c5bfd85..946ef16 100644 --- a/utils/install_zsh.sh +++ b/utils/install_zsh.sh @@ -2,8 +2,13 @@ function install_zsh() { username=$1 - echo "[ UTILS ]: Installing zsh" + + echo "[ UTILS ]: Installing Zsh" sudo apt-get install -y zsh + # Set Zsh as the default shell for the user sudo chsh -s /usr/bin/zsh "$username" - echo "[ UTILS ]: Zsh installed succesfully and set as default shell for $username" + echo "[ UTILS ]: Installing Oh My Zsh for $username" + # Install Oh My Zsh + sudo -u "$username" sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" + echo "[ UTILS ]: Zsh and Oh My Zsh installed successfully and set as the default shell for $username" } diff --git a/web/setup_ufw.sh b/web/setup_ufw.sh index 58da75f..b2bda26 100644 --- a/web/setup_ufw.sh +++ b/web/setup_ufw.sh @@ -4,7 +4,8 @@ function setup_ufw() { echo "[ WEB ]: Started UFW Firewall setup" sudo apt-get install -y ufw sudo ufw allow 22 + sudo ufw allow 80 sudo ufw allow 443 sudo ufw enable - echo "[ WEB ]: UFW Installed succesfully. Open ports SSH:22 - HTTPS:443" + echo "[ WEB ]: UFW Installed succesfully. Open ports SSH:22 - HTTPS:443 - HTTP:80" }