Skip to main content

One post tagged with "linux"

View All Tags

· One min read

I often want to create new users in Linux for testing. Creating new users without interaction can be challenging to automate because the passwd command provides no way for you to pass in a plain text password. It will prompt you for a password which is OK for interactive sessions but not suitable for automation (e.g. creating new users in Pulumi).

useradd --create-home --home-dir /home/$NEW_USER_NAME -s /bin/bash $NEW_USER_NAME
# New password:
# Retype new password:
# passwd: password updated successfully

The solution I have found is to pipe the password into the passwd command like this:

useradd --create-home --home-dir /home/$NEW_USER_NAME -s /bin/bash $NEW_USER_NAME

This trick allows you to create new users and set their passwords without interaction!