-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtermux-ssh
More file actions
executable file
·64 lines (60 loc) · 1.49 KB
/
Copy pathtermux-ssh
File metadata and controls
executable file
·64 lines (60 loc) · 1.49 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
53
54
55
56
57
58
59
60
61
62
63
64
#!/data/data/com.termux/files/usr/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
B="$(printf '\033[1;34m')"
RESET="$(printf '\033[0m')"
MARKER_FILE="$HOME/.first_pass_change_marker"
function start_ssh() {
sshd
sleep 2
ifconfig_output=$(ifconfig 2>/dev/null)
ip_address=$(echo "$ifconfig_output" | awk '/ccmni1/,/inet/ { if ($1 == "inet") print $2 }')
if [[ -z "$ip_address" ]]; then
ip_address=$(echo "$ifconfig_output" | awk '/ap0/,/inet/ { if ($1 == "inet") print $2 }')
fi
port=8022
if [[ -n "$ip_address" ]]; then
echo "${G}Your Address Is: ${B}$ip_address $port${RESET}"
else
echo "${R}No IP address found.${RESET}"
fi
}
function stop_ssh() {
if pgrep sshd > /dev/null; then
echo "${G}sshd is running. Stopping it...${RESET}"
pkill -f sshd
if ! pgrep sshd > /dev/null; then
echo "${G}sshd has been stopped.${RESET}"
else
echo "${R}Failed to stop sshd.${RESET}"
fi
else
echo "${G}sshd is not running.${RESET}"
fi
}
case $1 in
start)
if [[ ! -f "$MARKER_FILE" ]]; then
echo "${G}Enter your ssh password${RESET}"
passwd
touch "$MARKER_FILE"
fi
start_ssh
;;
stop)
stop_ssh
;;
--help|-h)
echo -e "
termux-ssh start to start ssh\n
termux-ssh stop to stop ssh\n
termux-ssh to set passwd and start ssh\n
"
;;
*)
echo "${G}Enter your ssh password${RESET}"
passwd
touch "$MARKER_FILE"
start_ssh
;;
esac