I am trying to write a linode stackscript, which is a bash file which is run as root when you build a new image. It can prompt for parameters such as USER, KEY and possibly, but not ideally, PASSWORD.

In the script I create a user "bob", then

adduser --disabled-password --gecos "" --shell /bin/bash $USER
adduser $USER sudo 

We are creating the user with certificate and with no password, the user, once logged in via SSH, cant sudo as it prompts for a password that doesnt exist.

I assume there are 2 options here:

  1. give it a password. Unfortunately, there is no option to do this via parameter, so is there a way to do it without prompts (not interactive)?
  2. fix it so bob doesn't need to enter a password.

Instead disabling password, create a user without password.


adduser --disabled-password --gecos "" --shell /bin/bash $USER usermod -g sudo $USER passwd -d $USER


I found a solution, using option 1. I had not heard of chpasswd, but it seems to work with the unattended script. Now the user has a password for sudo.

adduser --disabled-password --gecos "" --shell /bin/bash $USER adduser $USER sudo echo "$USER:$PASS" | sudo chpasswd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.