Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign in with Mongo shell without having password shown?

How can I sign into the Mongo shell without showing my password? Everything says to either use

mongo -u user -p password -authenticationDatabase admin

or

mongo
> use admin;
> db.auth('user', 'password')

I don't like either one. The first leaves a command in cmd's history. The second isn't in the history but it still displays on screen in plain text. I tried only specifying a user in hopes I'd get a password prompt that doesn't display characters as I type, but in both cases an error occurs.

Is there a way to sign into Mongo in a way that doesn't put my password on the screen or store it in an insecure file (like a .bat or anything)?

I'm operating in Windows 7.

like image 880
Corey Ogburn Avatar asked Jul 31 '14 17:07

Corey Ogburn


2 Answers

If you add a flag -p but you don't specify a password, MongoDB shell will prompt you for a password.

mongo -u user -p --authenticationDatabase admin 

The password will be hidden as you type and will not be recorded in the shell history.

like image 194
Christian P Avatar answered Nov 15 '22 22:11

Christian P


mongo admin -u admin -p works (with the least typing), as noted by Corey.
The 1st "admin" is the database, and the 2nd "admin" is the user.

like image 40
Abel Wenning Avatar answered Nov 15 '22 20:11

Abel Wenning