Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set blank password for PostgreSQL user

I use postgresql command 'createuser myusername'. It prompts me for password always. If I leave password blank it gives an error that no password is specified.

I simply want to create a user with blank/no password and I'm not able to do it with Postgresql 9 under mac os x.

What steps should I take to create a user with no password. The command always asks me to enter a password.

like image 316
othman Avatar asked Mar 24 '11 15:03

othman


People also ask

What is the default password for postgres user?

For most systems, the default Postgres user is postgres and a password is not required for authentication. Thus, to add a password, we must first login and connect as the postgres user.

How do I encrypt passwords with PostgreSQL?

When creating a new user, we can use the crypt function to encrypt the password. INSERT INTO users (email, password) VALUES ( '[email protected]', crypt('johnspassword', gen_salt('bf')) ); The crypt function accepts two arguments: The password to encrypt.


1 Answers

Fixing this with createuser won't work. Per the man page for createuser, it says that login will fail if you really need a password and set --no-password. createuser just creates a user. It does not decide how the user will have to authenticate.

Authentication is handled mainly in pg_hba.conf, which decides whether or not to require passwords at login. I've never run PostgreSQL on OS X. On Linux, my distro's stock conf looks like this:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD  # "local" is for Unix domain socket connections only local   all             all                                     ident # IPv4 local connections: host    all             all             127.0.0.1/32            trust # IPv6 local connections: host    all             all             ::1/128                 trust 

Make sure you have something like the first line for for development access. Note: psql will try to connect with a unix socket if there is no --host option set. The second line would be used if you try to connect with psql --host localhost

like image 158
nate c Avatar answered Sep 21 '22 23:09

nate c