更新 'cg_init_machine.sh'

This commit is contained in:
toby 2023-03-26 16:09:18 +08:00
parent e6d6467e4c
commit 2a4fac5f3a
1 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,21 @@
#!/bin/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 getent group wheel || groupadd wheel
useradd cg_maintain_user useradd cg_maintain_user
if command -v groupmems &> /dev/null if command -v groupmems &> /dev/null
@ -9,7 +26,8 @@ else
fi fi
echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' | EDITOR='tee -a' visudo echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' | EDITOR='tee -a' visudo
mkdir -p /home/cg_maintain_user/.ssh mkdir -p /home/cg_maintain_user/.ssh
touch /home/cg_maintain_user/.ssh/authorized_keys 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 chown -R cg_maintain_user:cg_maintain_user /home/cg_maintain_user
chmod 600 /home/cg_maintain_user/.ssh/authorized_keys chmod 600 /home/cg_maintain_user/.ssh/authorized_keys