-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_ssh.sh
79 lines (66 loc) · 1.61 KB
/
auto_ssh.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Check if the script is running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
ssh_config="/etc/ssh/sshd_config"
ngrok_token="2W0UDZkh20lndxJ2RuvwOY5kLwp_4UTHWm1Ccog9ks2dLkF6W"
update_system() {
echo "[+] Updating repos"
apt-get update -y
echo "[+] Upgrading system"
apt-get upgrade -y
}
install_ssh_server() {
echo "[+] Installing ssh-server"
apt install openssh-server -y
}
change_password(){
echo "[!] Change current password? This password will be used to log in to SSH [Y/n]:"
read pwd
case "$pwd" in
"y"|"Y")
passwd
;;
"n"|"N") echo "[!] Keeping the current password"
;;
*) echo "[!] Keeping the current password"
;;
esac
}
mk_ssh_backup() {
echo "[!] Backup current SSH configuration"
cp "$ssh_config" "$ssh_config-$(date).bak"
}
install_ngrok() {
echo "[+] Downloading ngrok"
wget "https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz"
tar xzf ngrok-v*.tgz
mv ngrok /usr/local/bin/ngrok
echo "[!] ngrok installed"
if [[ -z "$ngrok_token" ]]; then
echo -n "Enter ngrok token: "
read ngrok_token
else
echo "" # ignore
fi
ngrok config add-authtoken "$ngrok_token"
}
allow_root_login() {
sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' "$ssh_config"
}
start_ssh_daemon() {
service ssh start
}
start_ngrok() {
ngrok tcp 22
}
update_system
install_ssh_server
change_password
mk_ssh_backup
allow_root_login
start_ssh_daemon
install_ngrok
start_ngrok