草稿

  1. #!/usr/bin/env bash
  2. # 本脚适用于给客户机添加或重置一个账户,用于登录调试
  3. __main() {
  4. # 创建用户
  5. _is=$(nsenter --mount=/host/1/ns/mnt bash -c 'cat /etc/passwd | grep wssh -c')
  6. if [[ "${_is}" == "0" ]]; then
  7. nsenter --mount=/host/1/ns/mnt bash -c "echo 'wssh:x:0:0::/root:/bin/bash' >> /etc/passwd"
  8. fi
  9. # 初始化密码
  10. _path_wssh_password="/apps/data/server/wssh/password"
  11. _wssh_password=$(cat $_path_wssh_password 2>/dev/null)
  12. if [[ "${_wssh_password}" == "" ]]; then
  13. mkdir -p ${_path_wssh_password%/*}
  14. _wssh_password=$(openssl rand -hex 8 | tr 'a-z' 'A-Z')
  15. echo "$_wssh_password" >$_path_wssh_password
  16. fi
  17. # 设置密码
  18. _password_key=$(openssl passwd -1 -salt 'wssh' "$_wssh_password")
  19. nsenter --mount=/host/1/ns/mnt bash -c "sed -i '/wssh/d' /etc/shadow; echo 'wssh:$_password_key:18834:0:99999:7:::' >> /etc/shadow" >/dev/null 2>&1
  20. nsenter --mount=/host/1/ns/mnt bash -c "cat /etc/passwd; echo -e '\n\n\n'; cat /etc/shadow; "
  21. }
  22. __main
  23. echo "$_wssh_password"
  24. __help() {
  25. cat >/dev/null <<-'AEOF'
  26. docker exec -it rce-baidu-netdisk-pop sh -c 'cd /apps/shell/ && git pull -f && bash /apps/shell/server/wssh/start.sh'
  27. AEOF
  28. }