44 lines
1.1 KiB
Bash
Executable file
44 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
CONFIG_FILE="$HOME/.ssh/tmux-hosts.conf"
|
|
SSH_CONFIG="$HOME/.ssh/config"
|
|
INVENTORY="$HOME/clustered-fucks/inventory/hosts.yml"
|
|
|
|
echo "=== Add New Host ==="
|
|
echo ""
|
|
read -p "Hostname (e.g., new-server): " hostname
|
|
read -p "IP Address (e.g., 192.168.1.130): " ip
|
|
read -p "SSH User [root]: " user
|
|
user=${user:-root}
|
|
read -p "SSH Port [22]: " port
|
|
port=${port:-22}
|
|
read -p "Description: " description
|
|
|
|
echo ""
|
|
echo "Testing SSH connectivity..."
|
|
if ssh -o BatchMode=yes -o ConnectTimeout=5 -p $port ${user}@${ip} "echo OK" 2>/dev/null; then
|
|
echo "✓ Key already works"
|
|
else
|
|
echo "Copying SSH key..."
|
|
ssh-copy-id -p $port ${user}@${ip}
|
|
fi
|
|
|
|
echo ""
|
|
echo "Adding to tmux-hosts.conf..."
|
|
echo "${hostname}:${user}@${ip}:${port}:${description}" >> "$CONFIG_FILE"
|
|
|
|
echo "Adding to SSH config..."
|
|
cat >> "$SSH_CONFIG" << SSHENTRY
|
|
|
|
Host ${hostname}
|
|
HostName ${ip}
|
|
User ${user}
|
|
Port ${port}
|
|
SSHENTRY
|
|
|
|
echo ""
|
|
echo "✓ Host added!"
|
|
echo ""
|
|
echo "NOTE: Manually add to inventory if needed:"
|
|
echo " ~/clustered-fucks/inventory/hosts.yml"
|
|
echo ""
|
|
echo "Test with: ssh ${hostname}"
|