PostgreSQL without password prompt : .pgpass ignored - linux

I'm trying to enable root (Ubuntu 8.04) to use psql command without password prompt (for scripting purpose). Everything worked fine with PostgreSQL 8.3, but I migrate to PostgreSQL 8.4 and the login without password doesn't work anymore.
I've a correct .pgpass file (the same used for 8.3), the right of /root/.pgpass are 0600 but calling psql keep asking for a password.
NB : the PGPASSFILE variable is empty, so I assume that the .pgpass file is supposed to be used.
Any brilliant idea?

Try to check if this works:
*:*:*:postgres:password_for_postgres_user
And then try:
VERBOSITY=verbose psql --no-password --user postgres
This question should probably be migrated to serverfault.com.

Related

postgreSQL password authentication failed for user

I'm taking a full WebDev course and got really hard stuck on this matter. I've installed postgreSQL 14.2 for Windows 10 and the instructor said that pgAdmin4 would come together, which it didn't, so then i installed pgAdmin4 individually. I've setted everything up and created a testing database, which is called 'test', and also a table, everything through Windows Powershell command lines, following the course instructions. Now, when i try to access this database through PowerShell command psql 'test' and type the requested password for the OS user i get a Fatal Error, which follows:
PS C:\Users\theu_\desktop> psql 'test'
Password for user theu_:
psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "theu_"
I've tried my OS username password and the postgreSQL password, none of them works. What am i missing or did wrong?
Thanks in advance
Try accessing postgres by using psql -U postgres in cmd, postgres being the name of the superuser for postgres itself (if you did a basic install) - while windows is probably trying to access postgres with your windows name.
You should also be able to use SQL Shell to access your database without denoting a user.

Google Compute Engine instance requires password for sudo - what is my password?

I have a new google compute engine instance. I am SSH'ed into the instance using certs. Whenever I try to use sudo it asks for the primary user's password which I do not have. Just recently I setup an instance on centos 7 and did not have this issue.
The instance is running centos 8. Normally, I would ssh to the instance, then execute commands using Sudo. For example, I would like to set the root password.
if I run sudo passwd, sudo su - or even sudo cat /var/log/messages it asks me for the primary user's password. The problem is I do not have that password.
[primaryuser#server4 log]$ **sudo cat messages**
**[sudo] password for primaryuser:**
##########
[primaryuser#server4 log]$ **sudo passwd**
**[sudo] password for primaryuser:**
I expected to run the commands using sudo but do not have the password.
Does anyone have any ideas? I read other posts about similar problems but different from mine.
I had to give up and use ubuntu. Everything acted as expected on ubuntu and I was able to set the password. I believe the problem is limited to centos 8 but I am not certain.

Unable to Automate PostgreSQL Login on Linux Server

I've seen a few related questions here and tried pretty much all the solutions but there's obviously something silly I'm still missing. I'm trying to bypass the need to log in to PostgreSQL using a script. Its a pretty basic script to copy a text file on the server into a table in my database, and works fine except it prompts me to log in to PostgreSQL every time I run it. I intend to write a cron job that performs this task daily so the process needs to be automatic. Here's the script.
export PGPORT=5432
export PGDATABASE=db_name
export PGUSER=user
export PGPASSWORD=my_password
psql -h host_name -p 5432 -U user -W db_name -c "\COPY schema.table_name (col1, col2, col3, col4)
from path_to_txt_file with DELIMITER '^'"
I also went down the ".pgpass file" route to no avail. I saved it in /home/usr/.pgpass, and gave it the following credentials
*:*:*:user:my_password
saved it and then gave it permissions as follows
sudo chmod 600 .pgpass
I'm not sure if this is relevant but what I have as "usr" in my file path to the .pgpass file is different to my database username; what I have here as "user". Also the script I am running is in a completely different directory on the server to the .pgpass file. These are all novice points i'm sure but for the sake of being complete I thought I'd add them.
If there was a way to modify the existing script so that it didn't prompt me for a password that would be great, otherwise if anyone has any guidance on what I might be doing wrong with the .pgpass file I'd appreciate it.
Thanks in advance
I think the issue is option "-W" in the document of PostgreSQL, "-W" means "Force psql to prompt for a password before connecting to a database."
I suggest you to use this
export PGPORT=5432
export PGDATABASE=db_name
export PGUSER=user
export PGPASSWORD=my_password
psql -h host_name -p $PGPORT -U $PGUSER -d $PGDATABASE -c "\COPY schema.table_name(col1,
col2, col3, col4) from path_to_txt_file with DELIMITER '^'"
In addition to what Mabu said:
Postgresql has all it takes to automate logins and to be able to keep the connection parameters out of your code.
In addition to the .pgpass file for the password you can define all your connection parameters in a service file
I think the issue here is that my pg_hba.conf file needed to be edited to include the username that I am trying to access the database with. Unfortunately the database sits on an AWS RDS server instance, where the pg_hba.conf file is not editable. As well as manually going into the instance and trying to edit it without success, there is also mention of this here: https://serverfault.com/questions/560596/how-do-a-i-edit-conf-file-for-a-postgres-aws-rds. It will probably come down to building an EC2 instance where these configuration files are accessable.
I stand corrected with my answer above. The .pgpass file was just located in the wrong directory. I log into my linux server with the user name ubuntu, so after moving the .pgpass file into /home/ubuntu and deleting the PGPASSWORD line from the script above (the .pgpass file will be ignored if this is left in the script..) it now works perfectly. Looking at it now, it all seems quite obvious. I hope this might save someone a bit of stress in the future.

Installing Postgresql and PgAdmin3 on Linux

I use Postgesql and PgAdmin on Windows without any problems but am struggling to get it working on Linux (I'm a Linux N00b). I have installed the 64bit version on my Fedora box following these instructions (except substituting version 9.3 for 9.2). Everything works well until I get to launching pgsql with:
sudo -u postgres psql template1
Here I get an error "Permission denied" as is attempts to change to my home directory.
I can change the password for 'postgres' as per the instructions and I presume this is just so I can use 'md5' rather than 'trust' in pg_hba.conf (if not, then I don't understand why I need this step).
When I fire up PgAdmin3, initially I have no connections. Attempting to connect to the server gives me an authentication error for user 'postgres'. I have tried resetting pg_hba.conf to 'trust' but that doesn't work either.
I would appreciate an explanation of the 'postgres' user in Linux as it appears to be a separate actual user on the Linux system (unlike Windows where it is just a 'disembodied' user relevant only to Postgress). Secondly, help in getting PgAdmin speaking to Postgresql would be gratefully received.
psql -U postgres template1
It will prompt for password if you set md5 in pg_hba.conf
After much digging about I found that most of the documentation is incomplete. I needed a combination of connecting via Cefull Lo's solution (+1) and NOT (as in most of the documentation):
sudo -U postgres psql
Then to change the password I need a more explicit SQL command as follows
template1=# ALTER USER postgres with encrypted password ‘yourpassword’;
I presume that I need to explicitly state 'with encrypted password' because I am using md5, though again, 90% of the documentation fails to point this out and advises a basic change of password together with md5. Maybe this is specific to Fedora, who knows, but now I can connect via PgAdmin3.

Forgot Username / Pwd to CouchDB

Does anyone know how can I reset the username and password for CouchDB ?
This worked for me:
while couchdb is stopped,
clear the [admin] section in your */etc/couchdb/local.ini
delete the _users.couch database (located in */var/lib/couchdb/)
This will reset the user database to factory defaults (admin party!) and wipe all of couchdb's user accounts. There might be a more subtle way
With Apache CouchDB, admin accounts passwords can be changed by editing a file local.ini in the CouchDB config folder (/etc/couchdb/ on most Linux installs). [1]
Look for the [admin] section, which will list the all admin usernames, along with their hashed passwords:
[admin]
foo = -pbkdf2-0e0e83f911c970565fc988497a657bdc21a005e8,19ecef0bea1caf8d7f08fb791379c686,10
Replace the password hash with a new clear text password:
foo = bar
Now restart CouchDB (sudo restart couchdb on Ubuntu). CouchDB will notice the clear text password on startup and automatically replace it with the hashed version.
What I've done it's quite simple. I found out my old username and password here:
/opt/couchbase/var/lib/couchbase/config/config.dat
After that I went to opt/couchbase/bin/ and run
./couchbase-cli cluster-init -c localhost:8091 -u old_user -p old_password --cluster-init-username=new_user --cluster-init-password=new_password
Done!
Also you can check this: http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-faq.html
For mac users, base folder is /Library/Application Support/couchdb
One more point to add ...
If you are running Couch DB on Windows, then probably it was installed as a service and to reset it you need to stop service first, within running service other answers do not work.
http://www.7tutorials.com/what-are-windows-services-what-they-do-how-manage-them
Open Control Panel - Administrative Tools - Services and stop Apache Couch DB
for Unix:
http://silviud.blogspot.com/2012/10/couchbase-recover-web-console-password.html
/opt/couchbase/bin/erl \
-noinput -eval \
'case file:read_file("/opt/couchbase/var/lib/couchbase/config/config.dat") of {ok, B} -> io:format("~p~n", [binary_to_term(B)]) end.' \
-run init stop | grep cred
You just need to add the username and password in CouchDB local.ini file. You can add as many administrators as you want.
sudo nano /etc/couchdb/local.ini
and in the end of file, add username and password.
And don't forget to restart the CouchDB server.
sudo service couchdb restart
On Mac OS X, cbreset_password is not in PATH by default, so I've done just:
"/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/bin/cbreset_password" 127.0.0.1:8091
...and re-set the password once confirming yes
You can change couchbase localhost password by using following steps:
1. Install crul(for windows)
2. curl -u Administrator:password http://localhost:8091/controller/changePassword -d password=admin123
ubuntu 20.04 :
apt purge couchdb
apt install couchdb
was the only thing that worked for me.
If using 3.2, CouchDB server administrators and passwords in the last [admins] section that CouchDB finds when loading its ini files:
/opt/couchdb/etc/local.ini or
/opt/couchdb/etc/local.d/10-admins.ini
Don't forget to restart CouchDB:
sudo systemctl restart couchdb (if using ubuntu)
source: https://docs.couchdb.org/en/3.2.0/config/auth.html

Resources