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.



enter image description here



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.





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







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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)