I need a little help with mongo.
I installed 2.4.9 version from accroding to this instructions:
For ubuntu - http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
For Debian - http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/
I followed manuals and documentation. Everything worked fine but when I change mongo settings to "auth=true" permissions go crazy.
Here is my user:
{
"_id" : ObjectId("5305dd8729ae7b95a4bde944"),
"user" : "root",
"pwd" : "063bbfd478f7b78df6c93b6202af9145",
"roles" : ["clusterAdmin", "userAdminAnyDatabase",
"readWriteAnyDatabase", "dbAdminAnyDatabase" ] }
I used rockmongo. And when I open my mongodb it says that I don't have enough permissions to run command db.getCollectionNames()
It says: Execute failed:unauthorized
And the same thing for creating users, managing databases.
I can't imagine what more permissions should I provide to user.
As it is said in manual this user is the first one I created. I gave him all highest admin privileges.
After changing auth parameter to auth=true
I also can't login in command line.
$ mongo -uroot -p <my password> --host 127.0.0.1
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
Thu Feb 20 11:56:17.510 Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } at src/mongo/shell/db.js:228
exception: login failed
By the way I tried password with and without braces. With long option and short one. This way -p<my password> and this way -p <my password>
But application (use simple db users) works fine.
I created database and two users (before making auth=true) and they seems fine for applications that use them.
I couldn't google any information. In most cases adding clusterAdmin or other permissions solves the problem for them.
OS: Ubuntu 12.04 and Debian 7 (In both same behavior)
MongoDb: 2.4.9
What is my mistake?
Did you create the user on the admin database?
clusterAdmin and the *AnyDatabase permissions apply only on the admin database.
When you authenticate, you'll need to authenticate against the admin database and then access other databases according to user's permissions.
mongo --authenticationDatabase admin -u root -p <my password> --host 127.0.0.1
Related
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.
I accidentally removed the super user privilege from user: postgres. I don't know how to get another super user. I stopped the postgres service and tried logging in with single-user mode:
/usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
I get this error:
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
In Linux, how can I start Postgres in single-user mode so I can fix the super user privilege?
Edit: I used this link for reference, but I'm getting the error mentioned above.
Accidently removed postgres default superuser privileges - can I get it back?
I combined solutions from these three links:
Accidently removed postgres default superuser privileges - can I get it back?
Restoring the superuser account on the postgres server
“root” execution of the PostgreSQL server is not permitted
After stopping the postgresql service, I ran this command:
sudo -u postgres /usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
/usr/pgsql-10/bin/postgres is the location of my postgres binary
/var/lib/pgsql/10/data is the location of my postgresql conf
This allowed me to access single user mode, where I just typed this command:
ALTER USER postgres SUPERUSER;
So if anyone is experiencing the same scenario as me, please give the posted command a try.
just adding this for postgresql 12 (Ubuntu) and possibly up
sudo -su postgres /usr/lib/postgresql/12/bin/postgres --single -D /etc/postgresql/12/main
I tried to connect to mLab on my terminal when I followed the instruction on the website
This is the command that I typed
mongo ds151461.mlab.com:51461/simplelogin -u <dbuser> -p <dbpassword>
This is the result I got:
MongoDB shell version v3.4.4
connecting to: mongodb://ds151461.mlab.com:51461/simplelogin
MongoDB server version: 3.2.13
WARNING: shell and server versions do not match
2017-06-12T19:12:35.498-0400 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1459:20
#(auth):6:1
#(auth):1:2
exception: login failed
Btw, when I run the local mongoDB, I use mongod to make it work and mongo does not work
As the error suggests you have an authentication error.
Which is possibly happening because you are using credentials of a user that is not valid for the database "simplelogin".
(You can't use mlab credentials here, I made this mistake, might help someone, so worth a mention.)
If you don't have a user in the database yet. Follow following steps to create a user.
1 - Go to your database page, by clicking on the database from the landing page.
Or use following url, https://mlab.com/databases/simplelogin (you have to be logged in for this to work)
2 - From there click the "Users" tab. Click on the button that says "Add database user", and enter username and password (lets say username - "myuser" and password - "mypassword" for this illustration). Click the "Create" button.
3 - Use those credentials to connect to your database.
mongo ds151461.mlab.com:51461/simplelogin -u myuser -p mypassword
And it should work.
Does this help?
I've installed MemSQL community edition (single host cluster) and all is working well. I need to allow remote access to the database, but MemSQL installs the user root without a password. If I open up the 3306 port on the firewall, memSQL happily allows anyone to log in as root without a password.
I've tried to change the root user password via
mysqladmin -u root -h 127.0.0.1 password abc123
but I get the error of
mysqladmin: unable to change password; error: 'Unknown system variable 'password''
I also tried to change after connecting as root. all of these fail:
mysql> SET PASSWORD = 'abc123';
ERROR 1193 (HY000): Unknown system variable 'PASSWORD'
mysql> SET PASSWORD = PASSWORD('abc123');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('abc123')' at line 1
mysql> SET PASSWORD = OLD_PASSWORD('abc123');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('abc123')' at line 1
So I'm stuck. The docs for MemSQL are pretty lightweight on this issue as well, and they don't seem to have a community page where I can ask about this. I figure it's something really simple that I'm trying to do, not sure why it's so difficult, and for that matter, I'm not sure why MemSQL defaults to no security at all.
Any ideas?
In the June 2015 release of MemSQL Ops, you can now change the root password with one command using the memsql-update-root-password command. See these links for more information:
http://docs.memsql.com/4.0/ops/cli/MEMSQL-UPDATE-ROOT-PASSWORD/
http://docs.memsql.com/4.0/admin/security/#adding-or-updating-the-root-password
I hope this helps!
In MemSQL to change a password of a user you should use the GRANT command:
grant all on *.* to 'root'#'localhost' identified by 'password' with grant option;
grant all on *.* to 'root'#'%' identified by 'password' with grant option;
Refer to the manual of the GRANT command and to a very detailed manual of configuring the cluster security:
http://docs.memsql.com/latest/ref/GRANT/
http://docs.memsql.com/latest/admin/security/#configuring-password-security
Try
mysql --user=root --password=abc123 --host=127.0.0.1
or
mysql -u root -p abc123 -h 127.0.0.1
Reference: Mysql man page.
You can change the root password with:
GRANT ALL ON *.* TO "root"#"%" IDENTIFIED BY 'password' WITH GRANT OPTION
I observed one strange thing while changing password for root user in mysql as below.
mysqladmin -u root password 'mypassword'
Got error as
mysqladmin: unknown variable 'database=mydatabase'
The reason for this is mydatabase variable has been set in the /etc/my.cnf file. I commented out that line, then everything works fine.
I though of sharing this in this thread.
I want to create user and database in linux server.
I am able to create user with the following code:
su - postgres
# createuser -S -D -R myUser
but when I tried to create database with code :
# createdb -U myUser -p 5432 myDatabase
I get following error:
createdb: could not connect to database postgres: FATAL: Ident authentication failed for user "myUser"
I am new to linux so I am unable to figure out why I was able to create user but while creating database there is connection error with postgres. And also error for ident
authentication for user.
I am new to linux so I am unable to figure out why I was able to create user but while
creating database there is connection error with postgres. And also error for ident
authentication for user.
ident is an authentication schema that relies on the currently logged in user. If you've su -s to postgres and then try to login as another user, ident will fail (as it's not the currently logged in user). You can solve this issue in two ways, I tend to use the latter.
solution: simply make sure the currently logged in user is the user with which you would like to log in to postgres:
postgres#machine:~$ createuser -S -D -R myUser
postgres#machine:~$ exit
machine:~# su - myUser
myUser#machine:~$ psql myDatabase
better solution: change pg_hba.conf (probably located in /etc/postgresql/8.4/main/ or similar), and make sure you add the "md5" authentication schema to the list of options. Here's my pg_hba.conf on my development box, without comments:
berry#berry-pc:~$ sudo cat /etc/postgresql/8.4/main/pg_hba.conf | grep -v "^#" | grep -v "^$"
local all postgres ident
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
This tells PostgreSQL that postgres can login with ident, and all other users can login using the md5 authentication. That way, you can use the -U switch to the psql binary to denote which user you wish to become, so this actually works:
berry#berry-pc:~$ psql -U myUser myDatabase.
That said, I tend to use the postgres superuser to create databases. I then grant permissions on the newly created database to the newly created user, as such:
postgres#debian:~$ psql template1
template1=# CREATE USER myUser WITH PASSWORD 'myPassword';
CREATE ROLE
template1=# CREATE DATABASE myDatabase;
CREATE DATABASE
template1=# GRANT ALL PRIVILEGES ON DATABASE myDatabase TO myUser;
GRANT
template1=# \q
Hope that helps.
ADDENDUM: Once you've altered the pg_hba.conf, you will have to restart the PostgreSQL server to make sure it reads the configuration again. You can do so by issuing this command:
root#debian:~$ /etc/init.d/postgresql-8.4 restart
The script might be called "postgresql" instead of "postgresql-8.4", depending on OS and method of installation.