我想在创建用户并指定其密码的远程虚拟机上执行命令。
使用 sshpass,我可以以 root 身份远程执行命令,例如
sshpass -p "rootpasswd" ssh root@remotevm '<remote command here>'
Run Code Online (Sandbox Code Playgroud)
所以我想创建一个用户,我可以用
adduser <username>
Run Code Online (Sandbox Code Playgroud)
接下来我想使用 usermod 创建密码:
usermod --password <encrypted_pass> <user>
Run Code Online (Sandbox Code Playgroud)
我希望能够指定密码香蕉 - 那么我如何加密字符串香蕉以便我可以将香蕉指定为用户的加密密码?
尝试chpasswd:
echo "user:password_here" | chpasswd
Run Code Online (Sandbox Code Playgroud)