Set encrypted postgres password without entering it as SQL

1.7k views Asked by At

I set up a postgres DB on my server, logged in with postgres (PEER Method), created another user and than want to set an encrypted password for the new user.

The most tutorials I find say, that you can change the password by:

ALTER USER other_user WITH ENCRYPTED PASSWORD 'passwd';

But it does not really feel good to enter the password clear into the sql console. It is saved in the history, and everybody can see it.

Is this really the right way to set a password in postgres?

1

There are 1 answers

2
bashman On

I have a ~/.pgpass in my home :

localhost:5432:*:postgres:123456

and the query file password.txt :

ALTER USER other_user WITH ENCRYPTED PASSWORD 'passwd';

and run this command:

psql -U useradmin -h localhost -w -a -E -f password.txt 

Remember:

rm .psql_history