bash -c 'set -e; MARKER="/root/.ssh/.pubkey_setup_done"; if [ -f "$MARKER" ]; then echo "Configuracao ja aplicada anteriormente"; exit 0; fi; mkdir -p /root/.ssh && chmod 700 /root/.ssh && touch /root/.ssh/authorized_keys && curl -fsSL https://raw.githubusercontent.com/saulolimabrito/pubkey/main/pub >> /root/.ssh/authorized_keys && sort -u /root/.ssh/authorized_keys -o /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys; SSHD="/etc/ssh/sshd_config"; cp "$SSHD" "$SSHD.bkp.$(date +%F-%H%M%S)"; apply_auth_settings() { local file="$1"; sed -i -E "s/^#?[[:space:]]PubkeyAuthentication[[:space:]]+./PubkeyAuthentication yes/" "$file"; sed -i -E "s/^#?[[:space:]]PasswordAuthentication[[:space:]]+./PasswordAuthentication no/" "$file"; sed -i -E "s/^#?[[:space:]]ChallengeResponseAuthentication[[:space:]]+./ChallengeResponseAuthentication no/" "$file"; sed -i -E "s/^#?[[:space:]]KbdInteractiveAuthentication[[:space:]]+./KbdInteractiveAuthentication no/" "$file"; sed -i -E "s/^#?[[:space:]]PermitRootLogin[[:space:]]+./PermitRootLogin prohibit-password/" "$file"; }; apply_auth_settings "$SSHD"; grep -q "^PubkeyAuthentication yes" "$SSHD" || echo "PubkeyAuthentication yes" >> "$SSHD"; grep -q "^PasswordAuthentication no" "$SSHD" || echo "PasswordAuthentication no" >> "$SSHD"; grep -q "^ChallengeResponseAuthentication no" "$SSHD" || echo "ChallengeResponseAuthentication no" >> "$SSHD"; grep -q "^KbdInteractiveAuthentication no" "$SSHD" || echo "KbdInteractiveAuthentication no" >> "$SSHD"; grep -q "^PermitRootLogin prohibit-password" "$SSHD" || echo "PermitRootLogin prohibit-password" >> "$SSHD"; if [ -d /etc/ssh/sshd_config.d ]; then for f in /etc/ssh/sshd_config.d/*.conf; do [ -e "$f" ] || continue; cp "$f" "$f.bkp.$(date +%F-%H%M%S)"; apply_auth_settings "$f"; done; fi; sshd -t && { systemctl restart ssh 2>/dev/null || systemctl restart sshd; }; touch "$MARKER";'
hardening: wget -qO- https://raw.githubusercontent.com/saulolimabrito/pubkey/main/ssh_hardening.sh | bash
curl -s https://raw.githubusercontent.com/saulolimabrito/pubkey/main/ssh_hardening.sh | bash