From c16d9743a2f19caac218877fe072e73e5f216fb4 Mon Sep 17 00:00:00 2001 From: Kristen Hercules Date: Tue, 9 Dec 2025 22:03:58 -0600 Subject: [PATCH] Push --- set-postgres-password.sh | 79 +++++++++++++++++++++++++++++++++ setup-postgres-remote-access.sh | 62 ++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100755 set-postgres-password.sh create mode 100755 setup-postgres-remote-access.sh diff --git a/set-postgres-password.sh b/set-postgres-password.sh new file mode 100755 index 0000000..eb40703 --- /dev/null +++ b/set-postgres-password.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# Interactive PostgreSQL Password Setup Script + +echo "==========================================" +echo "PostgreSQL User Password Setup" +echo "==========================================" +echo "" +echo "Available users:" +echo " 1. postgres (superuser - recommended)" +echo " 2. skyartapp" +echo " 3. songlyric_app" +echo " 4. songlyric_user" +echo "" +read -p "Select user number (1-4): " user_choice + +case $user_choice in + 1) + username="postgres" + ;; + 2) + username="skyartapp" + ;; + 3) + username="songlyric_app" + ;; + 4) + username="songlyric_user" + ;; + *) + echo "Invalid choice. Exiting." + exit 1 + ;; +esac + +echo "" +echo "Setting password for user: $username" +echo "" + +# Prompt for password (hidden input) +read -s -p "Enter new password: " password +echo "" +read -s -p "Confirm password: " password_confirm +echo "" + +if [ "$password" != "$password_confirm" ]; then + echo "" + echo "Error: Passwords do not match!" + exit 1 +fi + +if [ -z "$password" ]; then + echo "" + echo "Error: Password cannot be empty!" + exit 1 +fi + +# Set the password +echo "" +echo "Setting password..." +sudo -u postgres psql -c "ALTER USER $username PASSWORD '$password';" + +if [ $? -eq 0 ]; then + echo "" + echo "==========================================" + echo "Success! Password set for user: $username" + echo "==========================================" + echo "" + echo "You can now use these credentials in pgAdmin 4:" + echo " Host: 192.168.10.130" + echo " Port: 5432" + echo " Username: $username" + echo " Password: [the password you just entered]" + echo "" +else + echo "" + echo "Error: Failed to set password!" + exit 1 +fi diff --git a/setup-postgres-remote-access.sh b/setup-postgres-remote-access.sh new file mode 100755 index 0000000..be28199 --- /dev/null +++ b/setup-postgres-remote-access.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# PostgreSQL Remote Access Setup Script +# This script configures PostgreSQL for remote access from Windows pgAdmin 4 + +echo "==========================================" +echo "PostgreSQL Remote Access Setup Complete!" +echo "==========================================" +echo "" +echo "Server IP: 192.168.10.130" +echo "Port: 5432" +echo "" +echo "Available Databases:" +echo " - skyartshop (owner: skyartapp)" +echo " - church_songlyric (owner: postgres)" +echo " - postgres (default database)" +echo "" +echo "Available Users:" +echo " - postgres (superuser)" +echo " - skyartapp" +echo " - songlyric_app" +echo " - songlyric_user" +echo "" +echo "==========================================" +echo "Next Steps:" +echo "==========================================" +echo "" +echo "1. Set password for postgres user (if not already set):" +echo " sudo -u postgres psql -c \"ALTER USER postgres PASSWORD 'your_secure_password';\"" +echo "" +echo "2. Set password for other users if needed:" +echo " sudo -u postgres psql -c \"ALTER USER skyartapp PASSWORD 'your_secure_password';\"" +echo "" +echo "3. In pgAdmin 4 on Windows, create a new server:" +echo " - General Tab:" +echo " Name: Ubuntu Server PostgreSQL" +echo "" +echo " - Connection Tab:" +echo " Host: 192.168.10.130" +echo " Port: 5432" +echo " Maintenance database: postgres" +echo " Username: postgres (or any user you set password for)" +echo " Password: [the password you set]" +echo " Save password: [check if desired]" +echo "" +echo "4. Click Save to connect!" +echo "" +echo "==========================================" +echo "Security Notes:" +echo "==========================================" +echo "- Remote access is allowed from 192.168.10.0/24 network" +echo "- All connections use scram-sha-256 authentication" +echo "- Firewall (ufw) is currently inactive" +echo "- Backups saved to:" +echo " /etc/postgresql/16/main/postgresql.conf.backup" +echo " /etc/postgresql/16/main/pg_hba.conf.backup" +echo "" +echo "To restore original configuration:" +echo " sudo cp /etc/postgresql/16/main/postgresql.conf.backup /etc/postgresql/16/main/postgresql.conf" +echo " sudo cp /etc/postgresql/16/main/pg_hba.conf.backup /etc/postgresql/16/main/pg_hba.conf" +echo " sudo systemctl restart postgresql" +echo ""