From 41fec6d673842204c0a7f73f28b46276f9c1db1b Mon Sep 17 00:00:00 2001 From: toby Date: Wed, 29 Mar 2023 11:40:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'cg=5Finit=5Fmachine.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cg_init_machine.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cg_init_machine.sh b/cg_init_machine.sh index fc74d45..0075c6b 100644 --- a/cg_init_machine.sh +++ b/cg_init_machine.sh @@ -18,12 +18,8 @@ END getent group wheel || groupadd wheel useradd cg_maintain_user -if command -v groupmems &> /dev/null -then - groupmems -g wheel -a cg_maintain_user -else - usermod -a -G wheel cg_maintain_user -fi +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")" @@ -31,15 +27,21 @@ 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 +if command -v yum >/dev/null >/dev/null 2>&1 then - yum install -y net-snmp + sudo yum install -y net-snmp else - apt-get install -y snmpd + 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 -sudo firewall-cmd --zone=public --add-service=snmp --permanent -sudo firewall-cmd --reload + +if command -v firewall-cmd >/dev/null >/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