36 lines
1.0 KiB
Bash
Executable File
36 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# decrypt-passphrase.sh
|
|
# Automate PGP decryption of SSH passphrase and SSH connection
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
PGP_MESSAGE_FILE="${1:-/tmp/pgp_message.asc}"
|
|
SSH_KEY="${2:-/Users/robertrapp/Documents/Zertifikate/haslach_privat}"
|
|
SSH_USER="${3:-root}"
|
|
SSH_HOST="${4:-85.215.56.185}"
|
|
|
|
# Ensure GnuPG is in PATH
|
|
export PATH="/opt/homebrew/bin:$PATH"
|
|
|
|
# Step 1: Decrypt the PGP message
|
|
echo "🔓 Decrypting PGP passphrase..."
|
|
DECRYPTED_PASSPHRASE=$(printf '%s' "$(cat "$PGP_MESSAGE_FILE")" | gpg --batch --yes --decrypt 2>/dev/null)
|
|
|
|
if [ -z "$DECRYPTED_PASSPHRASE" ]; then
|
|
echo "❌ Failed to decrypt PGP message. Check that:"
|
|
echo " - The private GPG key is imported"
|
|
echo " - The PGP message is valid"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Passphrase decrypted successfully"
|
|
|
|
# Step 2: SSH into the server
|
|
echo "🔗 Connecting to $SSH_HOST as $SSH_USER..."
|
|
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$SSH_USER@$SSH_HOST" <<EOF
|
|
$DECRYPTED_PASSPHRASE
|
|
EOF
|
|
|
|
echo "✅ SSH connection completed"
|