49 lines
1.3 KiB
Bash
49 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
GET_KEY_CODE=$(cat <<END
|
|
#coding=utf-8
|
|
import urllib.request
|
|
import json
|
|
cfgsrc = urllib.request.urlopen("https://devms.t.educg.com/api/initpkey.do")
|
|
cfgtext = cfgsrc.read()
|
|
cfglines = json.loads(cfgtext.decode("utf8"))
|
|
|
|
for cfg in cfglines:
|
|
for key, value in cfg.items():
|
|
if(key=='name'):
|
|
continue
|
|
print(f'ssh-rsa {value} {key}')
|
|
END
|
|
)
|
|
|
|
getent group wheel || groupadd wheel
|
|
useradd cg_maintain_user
|
|
usermod -a -G wheel cg_maintain_user
|
|
|
|
echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' | EDITOR='tee -a' visudo
|
|
mkdir -p /home/cg_maintain_user/.ssh
|
|
res="$(python3 -c "$GET_KEY_CODE")"
|
|
echo "$res" >/home/cg_maintain_user/.ssh/authorized_keys
|
|
chown -R cg_maintain_user:cg_maintain_user /home/cg_maintain_user
|
|
chmod 600 /home/cg_maintain_user/.ssh/authorized_keys
|
|
|
|
if command -v yum >/dev/null 2>&1
|
|
then
|
|
sudo yum install -y net-snmp
|
|
else
|
|
sudo apt-get install -y snmpd
|
|
fi
|
|
|
|
sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.bak
|
|
sudo curl -L -o /etc/snmp/snmpd.conf https://git.tobyliu.com/toby/common-tools/raw/branch/main/snmpd.conf
|
|
sudo systemctl restart snmpd
|
|
|
|
if command -v firewall-cmd >/dev/null 2>&1
|
|
then
|
|
sudo firewall-cmd --zone=public --add-service=snmp --permanent
|
|
sudo firewall-cmd --reload
|
|
else
|
|
sudo ufw allow from any to any port 161
|
|
fi
|
|
|