First you have to switch to postgres user.
sudo -i -u postgresĀ
See the output.
Then type the command given below.
createuser --interactive
See the output. Just enter a user name (“john”) as you wish.
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.
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.
Done. The password has been added successfully. Check whether user was created by using any tool like pgAdmin.
Thanks.