-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_ssh_keys.sh
More file actions
executable file
·52 lines (43 loc) · 1.42 KB
/
setup_ssh_keys.sh
File metadata and controls
executable file
·52 lines (43 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Setup SSH keys for passwordless authentication
# Load configuration
if [ -f "config.env" ]; then
source config.env
else
echo "Error: config.env file not found. Please copy config.env.example to config.env and update with your values."
exit 1
fi
echo "=== Setting up SSH keys for passwordless authentication ==="
echo ""
# Generate SSH key if it doesn't exist
if [ ! -f $SSH_KEY_PATH ]; then
echo "Generating SSH key..."
ssh-keygen -t rsa -b 2048 -f $SSH_KEY_PATH -N ""
else
echo "SSH key already exists"
fi
echo ""
echo "Copying SSH key to VM1 ($VM1_IP)..."
echo "You'll be prompted for the $VM_USER password one last time for VM1"
ssh-copy-id $SSH_OPTS $VM_USER@$VM1_IP
echo ""
echo "Copying SSH key to VM2 ($VM2_IP)..."
echo "You'll be prompted for the $VM_USER password one last time for VM2"
ssh-copy-id $SSH_OPTS $VM_USER@$VM2_IP
echo ""
echo "Testing passwordless SSH to VM1..."
if ssh $SSH_OPTS $VM_USER@$VM1_IP "echo 'SSH key auth works for VM1'"; then
echo "✅ VM1 SSH key authentication successful"
else
echo "❌ VM1 SSH key authentication failed"
fi
echo ""
echo "Testing passwordless SSH to VM2..."
if ssh $SSH_OPTS $VM_USER@$VM2_IP "echo 'SSH key auth works for VM2'"; then
echo "✅ VM2 SSH key authentication successful"
else
echo "❌ VM2 SSH key authentication failed"
fi
echo ""
echo "=== SSH key setup complete! ==="
echo "Now you can run scripts without password prompts"