pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shane Ambler <pgsql@Sheeky.Biz>
To: Rajiv Rajaian <rajiv.pgsql@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: How to create a new user with password in commandline with no prompt for password
Date: Wed, 20 Feb 2008 18:36:16 +1030
Message-ID: <47BBDF78.7070801@Sheeky.Biz> (raw)
In-Reply-To: <238696420802192330g69e3c447jeadd1d3d31506eda@mail.gmail.com>
References: <238696420802192330g69e3c447jeadd1d3d31506eda@mail.gmail.com>

Rajiv Rajaian wrote:
> Hi all
> Im using postgresql-8.0.3-1.
> I need to create a new user in postgresql with password ..But it should not
> prompt me to get the password ..ie only through command line I've to give
> the password as input
> Steps i had done are as follows
> 
> [root@g151 ~]# su postgres -c "createuser -A -d  globus"
> could not change directory to "/root"
> CREATE USER

For adding a user in SQL with a password you can use -
CREATE ROLE name WITH [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password';

Using that from the command line you can -
echo "CREATE ROLE name....." | psql -U postgres
to bypass the password prompt.

> [root@g151 ~]# su globus -c "createdb rftDatabase"
> could not change directory to "/root"
> CREATE DATABASE
 >
 >
> Also in /var/lib./pgsql/data/pg_hba.conf I ve added the entry as
> 
> host    rftDatabase     "globus"        "172.16.10.151"  255.255.255.0   md5
> 
> Now when i tried to login to that database I got the following error
> 
> [root@g151 ~]# psql -U globus -d rftdatabase
> psql: FATAL:  Ident authentication failed for user "globus"

Your pg_hba.conf line above says a password must be used.
You can add a line with your no password account using trust to get past 
that.

The other way around that is to use a .pgpass file in your local home 
dir. http://www.postgresql.org/docs/8.3/interactive/libpq-pgpass.html 
for more detail.

> Also with password promt it was prompting password ..But I haven't created
> the user with password
>  [root@g151 ~]# psql -U globus -d rftdatabase -W
> Password:
 >
> 
> Is it possible to create any new user in postgresql with password through
> command line and with no prompt for password.??Is there any option in
> Postgresql?
> Also  if  I create  a new user with su postgres -c "createuser -A -d
> globus" .Will it set any default password while creating the user ??

No password is stored unless you specify it.


As much as these are ways around your inconveniences, you should also 
consider the security implications of using them.


-- 

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz



view thread (5+ messages)  latest in thread

Message-ID: <47BBDF78.7070801@Sheeky.Biz>
Permalink:  ../47BBDF78.7070801@Sheeky.Biz/
Also on:    postgresql.org/message-id/47BBDF78.7070801@Sheeky.Biz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: pgsql@Sheeky.Biz, rajiv.pgsql@gmail.com
  Subject: Re: How to create a new user with password in commandline with no prompt for password
  In-Reply-To: <47BBDF78.7070801@Sheeky.Biz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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