How to create a new user with a password in PostgreSQL in ubuntu 18.04

First you have to switch to postgres user.

 sudo -i -u postgresĀ  

See the output.

switch_user.png

Then type the command given below.

createuser --interactive 

 

See the output. Just enter a user name (“john”) as you wish.

create_user.png

Press enter.

Then system will ask to create this user with super user privileges. If you type “y” user will be created with super user privileges.

create_user_as_superuser.png

Done.

Now user “john” has been created successfully. Then we will add a password for user john.

psql -d template1 -c "ALTER USER john WITH PASSWORD 'newpassword';"

See the output.

create_user_password.png

Done. The password has been added successfully. Check whether user was created by using any tool like pgAdmin.

Thanks.

 

 

 

Leave a Comment