In this lesson, I will use Ubuntu to switch to the postgres user, create a new role/user and create a database. I will then use psql to alter user, giving her a password.
$ sudo -i -u postgres
$ createuser --interactive
... Next you will be asked:
✶ Enter the name of role to add:
✶ Is this a superuser?(y/n)
I am using the username 'candy' to match my linux username.
A superuser has special privlidges. I made candy a super user.
$ createdb candy
Create a database with the same name as the user.
$ psql
Welcome to the psql interface!
To give your user a password:
ALTER USER username WITH PASSWORD 'new_password';
➼ ALTER USER
We are going to change something about the user
➼ username
Here we will put the name of the user we wish to change.
➼ WITH PASSWORD
We are giving her a password
➼ 'new_password'
Here we put the password in quotes.
➼ ; (semi-colon)
Statements end with a semi-colon;
So, to give Candy the password 'candy':
ALTER USER candy WITH PASSWORD 'candy';
\q
Exit psql by typing '\q'
$ su candy
I switched back to my candy linux user account.