使用SSH隧道通过MongoDB Compass连接AWS上MongoDB实例时出现“command hostInfo requires authentication”错误,求助账号密码输入方法
Hey there! I totally get where you're stuck—you've got the SSH tunnel working, but Compass isn't asking for your MongoDB credentials, leading to that command hostInfo requires authentication error. Let's walk through how to add your database username and password correctly:
Step 1: Navigate back to the main connection tab
When you're in Compass's "Fill in connection fields individually" view, you probably jumped straight to the "More Options" tab for SSH settings. Now head back to the main tab (the first one, labeled "Connection").
Step 2: Enable username/password authentication
- Look for the "Authentication" section (it's usually near the top of the main tab).
- From the dropdown menu, select Username/Password (this is disabled by default, which is why you didn't see it earlier).
Step 3: Enter your MongoDB credentials
- Username: Input your
adminuser (the one you created in MongoDB). - Password: Type in the password associated with the
adminuser. - Authentication Database: Make sure this is set to
admin—since your user was created in the admin database, MongoDB needs to verify credentials against this database.
Step 4: Verify SSH tunnel settings and connect
Switch back to the "More Options" tab to double-check your SSH tunnel configuration (server address, username, PPK file) is still correct. Then click the "Connect" button again.
Why this works
The error you saw confirms the SSH tunnel is successful—Compass can reach the MongoDB instance, but it's trying to run commands like hostInfo without authentication. By adding your MongoDB credentials, you're giving Compass the permissions it needs to interact with the database.
内容的提问来源于stack exchange,提问作者Bulent Balci

