![我已经启用身份验证,但仍然可以无需用户名和密码连接到 MongoDB](https://linux22.com/image/791166/%E6%88%91%E5%B7%B2%E7%BB%8F%E5%90%AF%E7%94%A8%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%EF%BC%8C%E4%BD%86%E4%BB%8D%E7%84%B6%E5%8F%AF%E4%BB%A5%E6%97%A0%E9%9C%80%E7%94%A8%E6%88%B7%E5%90%8D%E5%92%8C%E5%AF%86%E7%A0%81%E8%BF%9E%E6%8E%A5%E5%88%B0%20MongoDB.png)
我的 /etc/mongod.conf 中有以下内容:
# set parameter options
setParameter:
enableLocalhostAuthBypass: false
# security options
security:
authorization: enabled
#keyFile: replace_me
我已使用systemctl restart mongod
并检查了 /var/log/mongodb/mongod.log 重新启动了 mongod 服务。最近有一行关于已读取配置且设置生效的内容:
{
"t": { "$date": "2023-11-26T10:39:15.483+00:00" },
"s": "I",
"c": "CONTROL",
"id": 21951,
"ctx": "initandlisten",
"msg": "Options set by command line",
"attr": {
"options": {
"config": "/etc/mongod.conf",
"net": {
"bindIp": "*",
"ipv6": false,
"port": 27017,
"tls": {
"certificateKeyFile": "/etc/ssl/mongodb.pem",
"mode": "requireTLS"
}
},
"processManagement": {
"fork": false,
"pidFilePath": "/var/lib/mongodb/mongodb.pid"
},
"security": { "authorization": "enabled" },
"setParameter": { "enableLocalhostAuthBypass": "false" },
"storage": { "dbPath": "/var/lib/mongodb", "directoryPerDB": false },
"systemLog": {
"destination": "file",
"logAppend": true,
"logRotate": "reopen",
"path": "/var/log/mongodb/mongod.log",
"quiet": false,
"verbosity": 0
}
}
}
}
看来我的设置已经生效了。为什么我不用用户名和密码仍然可以登录我的 mongod 服务?