-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminer_ssh
More file actions
executable file
·53 lines (43 loc) · 1.44 KB
/
miner_ssh
File metadata and controls
executable file
·53 lines (43 loc) · 1.44 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
# Check if IP address is provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <ip_address>"
exit 1
fi
INPUT="$1"
# If input is a single number, get local IP and replace last octet
if [[ "$INPUT" =~ ^[0-9]{1,3}$ ]] && [ "$INPUT" -ge 1 ] && [ "$INPUT" -le 254 ]; then
# Get local IP (macOS/BSD style)
LOCAL_IP=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n 1)
if [ -z "$LOCAL_IP" ]; then
echo "Could not determine local IP address."
exit 1
fi
# Replace last octet with input
IP_PREFIX=$(echo "$LOCAL_IP" | awk -F. '{print $1 "." $2 "." $3}')
IP="$IP_PREFIX.$INPUT"
else
IP="$INPUT"
fi
ssh-keygen -R $IP
SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
# Function to set terminal title
set_terminal_title() {
echo -ne "\033]0;$1\007"
}
set_terminal_title "Connecting to $IP"
# First attempt: Try root with empty password (will fail quickly if not allowed)
echo "Attempting to connect as root to $IP..."
if sshpass -p "" ssh $SSH_OPTIONS root@$IP "exit" 2>/dev/null; then
echo "Connected as root successfully"
set_terminal_title "root@$IP"
ssh $SSH_OPTIONS root@$IP
exit 0
fi
# Second attempt: Try miner with miner password
echo "Root login failed. Attempting to connect as miner..."
set_terminal_title "miner@$IP"
sshpass -p "miner" ssh $SSH_OPTIONS miner@$IP
# Reset terminal title on exit
set_terminal_title "Terminal"
exit $?