forked from solusvm-support/helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_accesskey.sh
55 lines (51 loc) · 1.57 KB
/
install_accesskey.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
#!/bin/bash
if [ $EUID -ne 0 ]; then
echo 'Run this script under root'
exit 1;
fi
case "$1" in
--help|help|-h)
echo "";
echo "Usage: $0 add/remove";
echo "";
exit 0;
;;
esac
KEY=''
flag=$1;
if [ "$flag" == 'add' ]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
IS_EXIST=$(cat ~/.ssh/authorized_keys | grep -w support@solusvm.com)
if [ "${IS_EXIST}" == "" ]; then
echo "Downloading SSH key..."
wget https://support.solusvm.com/hc/en-us/article_attachments/360013515211/id_rsa.pub -O /tmp/support-rsa-key >/dev/null 2>&1
echo "Downloading SHA Checksum..."
wget https://support.solusvm.com/hc/en-us/article_attachments/360014184691/id_rsa.checksum -O /tmp/support-rsa-key-checksum >/dev/null 2>&1
CHECKSUM=$(cat /tmp/support-rsa-key-checksum | awk '{ print $1 }')
KEYSUM=$(md5sum /tmp/support-rsa-key | awk '{ print $1 }')
if [ "${CHECKSUM}" == "${KEYSUM}" ]; then
KEY=$(cat /tmp/support-rsa-key)
echo "${KEY}" >> ~/.ssh/authorized_keys
rm -f /tmp/support-rsa-key
rm -f /tmp/support-rsa-key-checksum
echo "Key installed"
else
echo "Could not install Key. Checksum failed."
fi
else
echo "Key is already installed"
fi
chmod 600 ~/.ssh/authorized_keys
elif [ "$flag" == 'remove' ]; then
IS_EXIST=$(cat ~/.ssh/authorized_keys | grep -w support@solusvm.com)
if [ "${IS_EXIST}" == "" ]; then
echo "Key not found"
else
sed -i '/support@solusvm.com/ d' ~/.ssh/authorized_keys
echo "Key removed"
fi
else
echo "Usage: $0 add/remove"
fi