Change password Postgresql user using Chef recipe
Change password Postgresql user using Chef recipe
I need to set the password of my user postgres
during my POSTGRES installation cookbook on a CentOS 7 node.
postgres
From command line I execute the command
sudo passwd postgres
and the system ask me the new password and then to retype the password.
How may I "translate" this issue in a Chef recipe? Any example or documentation somewhere?
1 Answer
1
A correct way for setting a user password from non-interactively is to use chpasswd
instead of password
.
chpasswd
password
echo "postgres:CorrectHorseBatteryStaple" | sudo chpasswd
But actually setting password for postgres user on the server is not recommended. This is a system user - it should not be possible to login as postgres OS-level user with a password. You should use sudo su - postgres
or sudo -u postgres
instead.
sudo su - postgres
sudo -u postgres
Are you sure that the actual requirement is not about the "postgres" database superuser?
I don't know chef, so no ready-made recipe for you.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I'm following this guide postgresonline.com/journal/archives/… and it works, I've tried to execute manually all the steps and now I'd like to try to automate them. This guide says " .... Installing postgres creates a user account called postgres. If you want to change the password to something you know do this: sudo passwd postgres You'll be prompted for a new password. .... ". So I think that the user is a system user, May I avoid to define a password for the postgres user? .....
– Cesare
Aug 24 at 20:34