Enhance backup script to set default SSH password and skip key generation if they already exist
This commit is contained in:
@@ -15,6 +15,10 @@ if ! id -u "$SSH_USER" >/dev/null 2>&1; then
|
||||
adduser -D -s /bin/sh -h "/home/$SSH_USER" "$SSH_USER"
|
||||
# Ensure the user is properly initialized in shadow database
|
||||
passwd -u "$SSH_USER" 2>/dev/null || true
|
||||
# Add default ssh password if not set
|
||||
echo "$SSH_USER:$SSH_PASSWORD" | chpasswd
|
||||
else
|
||||
echo "User $SSH_USER already exists."
|
||||
fi
|
||||
|
||||
# Create necessary directories
|
||||
@@ -22,13 +26,16 @@ mkdir -p "$SSH_CONFIG_DIR" "$SSH_HOST_KEYS_DIR"
|
||||
|
||||
# Generate host keys if they don't exist
|
||||
for key_type in rsa ed25519; do
|
||||
key_file="$SSH_HOST_KEYS_DIR/ssh_host_${key_type}_key"
|
||||
echo "Generating $key_type host key..."
|
||||
ssh-keygen -t "$key_type" -f "$key_file" -N "" -q
|
||||
if [ -f "$SSH_HOST_KEYS_DIR/ssh_host_${key_type}_key" ]; then
|
||||
echo "Host key for $key_type already exists, skipping generation."
|
||||
continue
|
||||
else
|
||||
key_file="$SSH_HOST_KEYS_DIR/ssh_host_${key_type}_key"
|
||||
echo "Generating $key_type host key..."
|
||||
ssh-keygen -t "$key_type" -f "$key_file" -N "" -q
|
||||
fi
|
||||
done
|
||||
|
||||
# Add default ssh password if not set
|
||||
echo "$SSH_USER:$SSH_PASSWORD" | chpasswd
|
||||
|
||||
cat >"$SSH_CONFIG_FILE" <<EOF
|
||||
Port $SSH_PORT
|
||||
|
Reference in New Issue
Block a user