-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.sh
More file actions
158 lines (140 loc) · 7.38 KB
/
script.sh
File metadata and controls
158 lines (140 loc) · 7.38 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# Lumi's SSH key manager
#
# This script is used as a way to help users as fast as possible by instead of sharing their server's password, they add my SSH key, and I have access to their server.
# Idea inspired by Virtfusion, GPT-4o helped with this lol
# This is the new version of the script, accessible via:
# $ wget -qO- https://ssh.amogus.works/script.sh | bash
#
# We also have a legacy version of the script, which is no longer maintained, accessible via:
# $ wget -qO- https://ssh.amogus.works/old.sh | bash
#
# Have fun! Made with ❤️ by Lumi
help() {
echo -e "\033[92m● Usage:\e[0m"
echo -e " script.sh [add|remove|check|help]"
echo ""
echo -e "\033[92m● Options:\e[0m"
echo -e " \e[33m○ add\e[0m - Installs the SSH key."
echo -e " \e[33m○ remove\e[0m - Removes the SSH key."
echo -e " \e[33m○ check\e[0m - Checks if the SSH key is installed."
echo -e " \e[33m○ help\e[0m - Displays this help message."
echo ""
echo -e "\033[92m● GitHub Repository:\e[0m"
echo -e " \e[33m○ https://github.com/heyitslumi/ssh\e[0m"
exit 0
}
add() {
set +H
echo -e "\e[30;44;1m\e[1;37m[INFO]\e[0;38;5;250m hey! incase you still use this script, i now have a SSH.id key, which in my opinion is better for me since well... i don't know but if you can use it please-\e[0m"
echo -e "\e[30;44;1m\e[1;37m[INFO]\e[0;38;5;250m you can download my SSH.id keys at: https://sshid.io/lumi\e[0m"
echo -e "\e[30;44;1m\e[1;37m[INFO]\e[0;38;5;250m or put it directly in your .ssh/authorized_keys file using this lil command: curl -fs https://sshid.io/lumi >> ~/.ssh/authorized_keys\e[0m"
echo -e "\e[30;44;1m\e[1;37m[INFO]\e[0;38;5;250m there will be a timeout of 15 seconds just for you to give the time to read this\e[0m"
echo -e "\e[30;44;1m\e[1;37m[INFO]\e[0;38;5;250m thanks and have a nice day! :3\e[0m"
sleep 15
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
grep -F -e "[email protected]" -e "lumi's support key, check next_steps.txt in root directory for more" ~/.ssh/authorized_keys >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "\033[93m● Support SSH key is already installed!\e[0m"
else
echo -e "\e[36m○ Downloading support SSH key...\e[0m"
wget https://ssh.amogus.works/keys/ssh_key.pub -O "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi___key" >/dev/null 2>&1
echo -e "\e[36m○ Downloading support SSH key checksum...\e[0m"
wget https://ssh.amogus.works/keys/checksum/ssh_key.checksum -O "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi__key___check" >/dev/null 2>&1
echo -e "\e[36m○ Verifying SSH key with SHA1...\e[0m"
CHECKSUM=$(awk '{ print $1 }' "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi__key___check")
KEYSUM=$(sha1sum "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi___key" | awk '{ print $1 }')
if [ "${CHECKSUM}" == "${KEYSUM}" ]; then
echo -e "\033[92m● SSH key verification successful!\e[0m"
echo -e "\e[36m○ Installing SSH key...\e[0m"
SSH_KEY=$(cat "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi___key")
echo "${SSH_KEY}" >> ~/.ssh/authorized_keys
rm -f "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi___key"
rm -f "${TMP_DOWNLOAD_LOCATION}/__tmp___lumi__key___check"
echo -e "\033[92m● Support SSH key installed successfully!\e[0m"
echo ""
next_steps
echo ""
save_next_steps
else
echo -e "\e[1;31m● Support SSH key verification failed! SSH Key didn't match checksum!\e[0m"
fi
fi
echo -e "\e[36m○ Setting permissions...\e[0m"
chmod 600 ~/.ssh/authorized_keys
}
remove_ssh_key() {
grep -F -e "[email protected]" -e "lumi's support key, check next_steps.txt in root directory for more" ~/.ssh/authorized_keys >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\e[1;31m● Support SSH key not found!\e[0m"
else
sed -i '/[email protected]/d' ~/.ssh/authorized_keys
sed -i "/lumi's support key, check next_steps.txt in root directory for more/d" ~/.ssh/authorized_keys
echo -e "\033[92m● Support SSH key removed successfully!\e[0m"
fi
}
check_ssh_key() {
grep -F -e "[email protected]" -e "lumi's support key, check next_steps.txt in root directory for more" ~/.ssh/authorized_keys >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "\033[92m● Support SSH key IS installed.\e[0m"
echo -e "\033[92m○ To remove my support SSH key, run the following command:\e[0m"
echo -e " \e[33mwget -qO- https://ssh.amogus.works/script.sh | bash -s -- remove\e[0m"
else
echo -e "\033[93m● Support SSH key is NOT installed.\e[0m"
echo -e "\033[92m○ To add my support SSH key, run the following command:\e[0m"
echo -e " \e[33mwget -qO- https://ssh.amogus.works/script.sh | bash -s -- add\e[0m"
fi
}
next_steps() {
echo -e "\e[36m=========================================\e[0m"
echo -e "\033[92m Next Steps \e[0m"
echo -e "\e[36m=========================================\e[0m"
echo -e "\033[92m● What you can do next:\e[0m"
echo -e " \e[33m○ Share your server's IP Address:\e[0m If you need support and I asked you to run this script, please share your server's IP address, as well as your SSH port."
echo -e " \e[1;31m○ Please, do not share your server's password, as I will not use it. If you are still using passwords, I recommend migrating to SSH Keys. It's safer.\e[0m"
echo -e " \e[33m○ Remove the SSH key:\e[0m Use \`wget -qO- https://ssh.amogus.works/script.sh | bash -s -- remove\` if you no longer need the key."
echo -e " \e[33m○ Check key status:\e[0m Use \`wget -qO- https://ssh.amogus.works/script.sh | bash -s -- check\` to confirm if the key is installed."
echo -e " \e[33m○ Visit the repository:\e[0m Check out the GitHub repo at \e[33mhttps://github.com/heyitslumi/ssh\e[0m for updates."
echo -e "\e[36m=========================================\e[0m"
}
save_next_steps() {
cat <<EOF > ~/next_steps.txt
=========================================
Next Steps
=========================================
● What you can do next:
○ Share your server's IP Address:
If you need support and I asked you to run this script, please share your server's IP address, as well as your SSH port.
○ Please, do not share your server's password, as I will not use it. If you are still using passwords, I recommend migrating to SSH Keys. It's safer.
○ Remove the SSH key:
Use \`wget -qO- https://ssh.amogus.works/script.sh | bash -s -- remove\` if you no longer need the key.
○ Check key status:
Use \`wget -qO- https://ssh.amogus.works/script.sh | bash -s -- check\` to confirm if the key is installed.
○ Visit the repository:
Check out the GitHub repo at https://github.com/heyitslumi/ssh for updates.
=========================================
EOF
echo -e "\033[92m● This has also been saved to next_steps.txt.\e[0m"
}
SSH_KEY=''
TMP_DOWNLOAD_LOCATION=$(mktemp -d)
OPTION=$1
case "$OPTION" in
add)
add
;;
remove)
remove_ssh_key
;;
check)
check_ssh_key
;;
--help|help|-h)
help
;;
*)
echo -e "\e[1;31m● Invalid command or argument! Run the same script with the --help argument for the command list.\e[0m"
;;
esac