0

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?

user1383029
  • 1,685
  • 2
  • 19
  • 37
  • Not everyone, only people you are willing to allow super user access. If you have a bunch of people logging in with super user access, then you have much bigger problems that this one. – Joshua D. Drake Jun 14 '15 at 18:41
  • Hehe, yes, you are right, nobody has access to it. It just does not feel right to save it in plain text in a history. – user1383029 Jun 15 '15 at 05:51

1 Answers1

1

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
bashman
  • 138
  • 2
  • 11