Home > database >  Postges command exection without password
Postges command exection without password

Time:02-12

I want to use rundeck to allow app user to reset their own password without admin access. So I would like to execute this type of command:

export PASSFILE=/usr/pgsql-13/.pgpass ; /usr/pgsql-13/bin/psql -h hostname -U postgres -c """alter user ${job.username} PASSWORD '${option.Password}';"""

But the script fails because postgres ask for password Any one have a workaround? The postgres DB is not a classic DB but aws aurora DB, so I don't have access to pg_hba file

Many thanks

CodePudding user response:

If you want to use interactive commands on Rundeck you can use expect command, in that way you can "wrap" your command to "answer" any interactive command "question", that was answered here.

CodePudding user response:

The environment valuable is called PGPASSFILE.

An alternative and simpler way is to specify the passfile connection parameter:

/usr/pgsql-13/bin/psql 'host=hostname user=postgres passfile=/usr/pgsql-13/.pgpass' -c "alter user ${job.username} PASSWORD '${option.Password}';"

You can also use the password parameter to specify the password in the connect string.

  • Related