fix: resolve SSH key deployment issues
- Fix 'Bad substitution' error in check_deploy_ready.sh by replacing BASH_SOURCE with $0 - Add detailed SSH troubleshooting in check_deploy_ready.sh - Create fix_ssh_key.sh script to automate SSH key setup - Update documentation with new troubleshooting script
This commit is contained in:
parent
6aab887b50
commit
7fe6ed3baf
3 changed files with 103 additions and 3 deletions
|
|
@ -32,11 +32,27 @@
|
|||
./test_ci_locally.sh
|
||||
```
|
||||
|
||||
### `fix_ssh_key.sh`
|
||||
|
||||
Исправляет проблемы с SSH ключом для деплоя:
|
||||
|
||||
- Удаляет passphrase с SSH ключа
|
||||
- Устанавливает правильные права доступа
|
||||
- Копирует публичный ключ на сервер
|
||||
- Тестирует SSH подключение
|
||||
|
||||
```bash
|
||||
./fix_ssh_key.sh
|
||||
```
|
||||
|
||||
## Использование
|
||||
|
||||
### Перед деплоем
|
||||
|
||||
```bash
|
||||
# Если проблемы с SSH ключом
|
||||
./fix_ssh_key.sh
|
||||
|
||||
# Всегда проверяйте готовность перед деплоем
|
||||
./check_deploy_ready.sh
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
set -e
|
||||
|
||||
# Change to project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
|
|
@ -54,8 +54,11 @@ if ssh -o ConnectTimeout=10 -o BatchMode=yes -i "$SSH_KEY" root@$SERVER_IP "echo
|
|||
print_status "SSH connection to server successful"
|
||||
else
|
||||
print_error "Cannot connect to server via SSH"
|
||||
echo " Make sure the public key is added to root@$SERVER_IP:~/.ssh/authorized_keys"
|
||||
echo " Run: ssh-copy-id -i $SSH_KEY.pub root@$SERVER_IP"
|
||||
echo " Possible causes:"
|
||||
echo " 1. SSH key has a passphrase - remove it with: ssh-keygen -p -f $SSH_KEY"
|
||||
echo " 2. Public key not added to server: ssh-copy-id -i $SSH_KEY.pub root@$SERVER_IP"
|
||||
echo " 3. Wrong permissions on ~/.ssh directory: chmod 700 ~/.ssh && chmod 600 ~/.ssh/*"
|
||||
echo " 4. Server firewall blocks SSH: check ufw status on server"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
|||
81
tools/scripts/fix_ssh_key.sh
Executable file
81
tools/scripts/fix_ssh_key.sh
Executable file
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Script to fix SSH key issues for deployment
|
||||
# Run this if check_deploy_ready.sh fails on SSH connection
|
||||
|
||||
set -e
|
||||
|
||||
SSH_KEY="${SSH_DEPLOY_KEY:-$HOME/.ssh/forgejo_deploy}"
|
||||
SERVER_IP="147.45.152.129"
|
||||
SERVER_USER="root"
|
||||
|
||||
echo "🔧 Fixing SSH key for deployment..."
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if key exists
|
||||
if [ ! -f "$SSH_KEY" ]; then
|
||||
print_error "SSH key not found at $SSH_KEY"
|
||||
print_info "Generate it first with: ssh-keygen -t ed25519 -C 'forgejo-deploy@memo-cards.online' -f $SSH_KEY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove passphrase from key
|
||||
print_status "Removing passphrase from SSH key..."
|
||||
if ssh-keygen -p -f "$SSH_KEY" -N ""; then
|
||||
print_success "Passphrase removed from SSH key"
|
||||
else
|
||||
print_warning "Could not remove passphrase (key might not have one)"
|
||||
fi
|
||||
|
||||
# Set correct permissions
|
||||
print_status "Setting correct permissions..."
|
||||
chmod 700 ~/.ssh
|
||||
chmod 600 "$SSH_KEY"
|
||||
chmod 644 "${SSH_KEY}.pub"
|
||||
print_success "Permissions set"
|
||||
|
||||
# Copy public key to server
|
||||
print_status "Copying public key to server..."
|
||||
if ssh-copy-id -i "${SSH_KEY}.pub" "$SERVER_USER@$SERVER_IP" 2>/dev/null; then
|
||||
print_success "Public key copied to server"
|
||||
else
|
||||
print_warning "ssh-copy-id failed, trying manual method..."
|
||||
ssh "$SERVER_USER@$SERVER_IP" "mkdir -p ~/.ssh && chmod 700 ~/.ssh"
|
||||
cat "${SSH_KEY}.pub" | ssh "$SERVER_USER@$SERVER_IP" "cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
|
||||
print_success "Public key added manually"
|
||||
fi
|
||||
|
||||
# Test connection
|
||||
print_status "Testing SSH connection..."
|
||||
if ssh -o ConnectTimeout=10 -o BatchMode=yes -i "$SSH_KEY" "$SERVER_USER@$SERVER_IP" "echo 'SSH test successful'" 2>/dev/null; then
|
||||
print_success "SSH connection works! ✅"
|
||||
else
|
||||
print_error "SSH connection still fails"
|
||||
print_info "Try manual connection: ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "SSH setup completed! 🎉"
|
||||
print_info "You can now run: ./check_deploy_ready.sh"
|
||||
Loading…
Reference in a new issue