3

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.
eos
  • 551
  • 4
  • 10
  • 27

2 Answers2

3

Instead disabling password, create a user without password.

workaround

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

Aroly7
  • 474
  • 2
  • 7
2

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

eos
  • 551
  • 4
  • 10
  • 27