Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres createuser with password from terminal

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?

like image 295
Anatol Avatar asked Feb 23 '17 15:02

Anatol


1 Answers

sudo -u postgres
psql -c "create role NewRole with login password 'secret';"
like image 61
Andomar Avatar answered Oct 02 '22 02:10

Andomar