pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedpsql - prompt for password
4+ messages / 4 participants
[nested] [flat]
* psql - prompt for password
@ 2024-05-30 08:07 Edwin UY <edwin.uy@gmail.com>
0 siblings, 3 replies; 4+ messages in thread
From: Edwin UY @ 2024-05-30 08:07 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
Hi,
Is createuser the only one I can use to create a user where it prompts for
a password? There is no alteruser though.
I want to use psql and \prompt but am lost on how to use it.
Basically just want to use it for running a psql script like for example -
ALTER USER spongebob WITH ENCRYPTED PASSWORD ':newpassword';
Regards,
Ed
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: psql - prompt for password
@ 2024-05-30 08:11 Holger Jakobs <holger@jakobs.com>
parent: Edwin UY <edwin.uy@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Holger Jakobs @ 2024-05-30 08:11 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
Am 30.05.24 um 10:07 schrieb Edwin UY:
> Hi,
>
> Is createuser the only one I can use to create a user where it prompts
> for a password? There is no alteruser though.
> I want to use psql and \prompt but am lost on how to use it.
> Basically just want to use it for running a psql script like for
> example - ALTER USER spongebob WITH ENCRYPTED PASSWORD ':newpassword';
>
> Regards,
> Ed
>
>
You can feed a command into psql for that.
Example:
echo "alter user spongebob password 'secret2'" | psql
Add arguments for psql, like -U -d -h -p as needed.
Regards,
Holger
--
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
Attachments:
[application/pgp-signature] OpenPGP_signature (202B, ../../b233fdfe-a3ca-f5a2-cee4-2bf9ad5d6376@jakobs.com/2-OpenPGP_signature)
download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: psql - prompt for password
@ 2024-05-30 08:17 Kashif Zeeshan <kashi.zeeshan@gmail.com>
parent: Edwin UY <edwin.uy@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Kashif Zeeshan @ 2024-05-30 08:17 UTC (permalink / raw)
To: Edwin UY <edwin.uy@gmail.com>; +Cc: pgsql-admin@lists.postgresql.org
Hi Edwin
You can use \prompt for this reason, following is the example.
You first use the \prompt to get the password and store into a variable
You can then user CREATE USER Command and supply the variable used with
\prompt to provide the password.
I hope this helps.
=# \prompt 'Enter password for new user: ' new_user_password
Enter password for new user: test
# CREATE USER spongebob WITH ENCRYPTED PASSWORD :'new_user_password';
CREATE ROLE
Regards
Kashif Zeeshan
Bitnine Global
On Thu, May 30, 2024 at 1:07 PM Edwin UY <edwin.uy@gmail.com> wrote:
> Hi,
>
> Is createuser the only one I can use to create a user where it prompts for
> a password? There is no alteruser though.
> I want to use psql and \prompt but am lost on how to use it.
> Basically just want to use it for running a psql script like for example -
> ALTER USER spongebob WITH ENCRYPTED PASSWORD ':newpassword';
>
> Regards,
> Ed
>
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: psql - prompt for password
@ 2024-05-30 11:01 Erik Wienhold <ewie@ewie.name>
parent: Edwin UY <edwin.uy@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Erik Wienhold @ 2024-05-30 11:01 UTC (permalink / raw)
To: Edwin UY <edwin.uy@gmail.com>; +Cc: pgsql-admin@lists.postgresql.org
On 2024-05-30 10:07 +0200, Edwin UY wrote:
> Is createuser the only one I can use to create a user where it prompts for
> a password? There is no alteruser though.
> I want to use psql and \prompt but am lost on how to use it.
> Basically just want to use it for running a psql script like for example -
> ALTER USER spongebob WITH ENCRYPTED PASSWORD ':newpassword';
Or use \password which has the benefit of not leaking the plaintext
password into the logs which would be the case if there's an error in
the ALTER USER command.
psql -c '\password spongebob'
--
Erik
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-05-30 11:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-05-30 08:07 psql - prompt for password Edwin UY <edwin.uy@gmail.com>
2024-05-30 08:11 ` Holger Jakobs <holger@jakobs.com>
2024-05-30 08:17 ` Kashif Zeeshan <kashi.zeeshan@gmail.com>
2024-05-30 11:01 ` Erik Wienhold <ewie@ewie.name>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox