Using the passwd command from within a shell script

前端 未结 13 997
遥遥无期
遥遥无期 2020-11-28 04:20

I\'m writing a shell script to automatically add a new user and update their password. I don\'t know how to get passwd to read from the shell script instead of interactively

13条回答
  •  北海茫月
    2020-11-28 04:52

    For those who need to 'run as root' remotely through a script logging into a user account in the sudoers file, I found an evil horrible hack, that is no doubt very insecure:

    sshpass -p 'userpass' ssh -T -p port user@server << EOSSH
    sudo -S su - << RROOT
    userpass
    echo ""
    echo "*** Got Root ***"
    echo ""
    #[root commands go here]
    useradd -m newuser
    echo "newuser:newpass" | chpasswd
    RROOT
    EOSSH
    

提交回复
热议问题