17

I'm using vagrant to setup a new Ubuntu machine. With provisioning I'm in the need to create a new postgres user. Currently I'm using:

sudo su postgres
createuser -P myuser

Unfortunately provisioning fails because a prompt needs to be filled with password (-P flag).

Is there a way to pass the password to createuser like createuser myuser --password test or echo test | createuser -P myuser?

1 Answer 1

20
sudo -u postgres
psql -c "create role NewRole with login password 'secret';"
Sign up to request clarification or add additional context in comments.

4 Comments

thanks! my problem is the db does not exist yet. is it possible to create the db and in this step also the user and password like createdb -E 'utf-8' -l en_US.utf8 -O testDB -T template0 AND create role NewRole with login password 'secret
Sure? Just run createdb before calling psql to create a role.
What privileges does this assign to the user?
Unsafe. ps(1) (and so on) disclose secret in process list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.