2

I have a script that works fine on Centos because useradd doesnt require a password to be set there and then, but the same script doesnt work on ubuntu servers as it requires this info.

I ideally want to force no password set on my script for the ubuntu servers or add a line where it sets the password during the useradd command.

If I just add sudo passwd user to my script this will only take effect after the useradd command which is too late.

Any ideas?

Matt B
  • 99
  • 1
  • 1
  • 8

1 Answers1

1

From man adduser:

--disabled-password
Like --disabled-login, but logins are still possible (for example using SSH RSA keys) but not using password authentication.

The default behaviour on useradd is to disable the password, so that one should already work.

Dale C. Anderson
  • 577
  • 1
  • 5
  • 13
  • perfect, now my next issue are these requests. Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] How can I get around this information being asked for? – Matt B Mar 16 '17 at 17:30
  • 1
    @MattB, Ask a new, separate question! :-D. The more questions you ask the more reputation you gain on the S.E. network, which lets you do more things. So it's good to keep things simple and separate. Also, `adduser` is a pretty Debian-specific utility, so you may want to switch over to askubuntu.com instead. Chances are, the question's already been answered. – Dale C. Anderson Mar 16 '17 at 18:42
  • Honestly though, if you're doing things with a script, it's probably better to do it with `useradd`, which can do things non-interactively much better than `adduser` can. I think `adduser` (being a perl script), was never intended to be scripted, but is just a helper for manual use. – Dale C. Anderson Mar 16 '17 at 18:59
  • @MattB - See http://askubuntu.com/questions/94060/run-adduser-non-interactively – Dale C. Anderson Mar 16 '17 at 20:15
  • as you can tell im new to all of this. But good news is I found the answer earlier and now my script works on both Centos and Ubuntu. Im started to hate ubuntu now also.... :P – Matt B Mar 16 '17 at 20:20
  • @Dale Anderson - If you then add a password to a user created with `adduser ... ----disabled-password USER`, will the password no longer be disabled? – Wimateeka Feb 08 '18 at 18:16
  • @Wimateeka correct. – Dale C. Anderson Feb 08 '18 at 21:13