Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm writing a shell script that will perform a pg_dump from one server, and later it will restore the dump into a database on another server.

To access the Postgres database on the first server, I use export PGPASSWORD in order to avoid a password prompt.

When I perform the restore on the Postgres database for the second server, I am prompted for a user password. I tried to re-declare export PGPASSWORD (since the password for this database is different), but this does not work. I'm suspecting it has something to do with the fact that I have to double SSH hop in order to access the second database:

export PGPASSWORD=******
perform pg_dump
...
export PGPASSWORD=********
cat out.sql | ssh -i .ssh/server1.pem [email protected] "ssh -i .ssh/server2 \
0.0.0.0 psql -U postgres -h localhost -p 5432 DBNAME"

The above results in:

Password for user postgres:
psql: FATAL:  password authentication failed for user "postgres"

Does anyone have any suggestions? Thanks!

share|improve this question

2 Answers

up vote 2 down vote accepted

You can create a file in your home directory with name .pgpass & give the password details there :

like :

cat .pgpass

hostname:port:database:username:password

localhost:2323:test_db:test_user:test123**

Try this one. Hope your problem will be solved.

share|improve this answer

The .ssh/environment file is what you want. I think that file needs to be on server1, though, and server2 needs to be configured to allow users to modify their environment (via the PermitUserEnvironment option. See man ssh under "ENVIRONMENT" for more details.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.