UserNotFound: Could not find user "root" for db "admin" mongodb

2022. 12. 14. 16:31웹개발/에러

결과 : 

문제가 두개인데 (1) admin 디비를 삭제해서 생긴 에러.

conf파일에 있는 security를 잠시 주석처리하고 재시작 후, mongod 들어가면 admin 다시 생긴 것 확인 가능.

들어가서 mongo 접속 계정 다시 만들고, 나와서 해당 계정으로 로그인.

(2) 각각의 데이터베이스에 접속 가능한 계정을 못찾음. 아마 오타낸 듯.

각각 디비에 들어가 각 유저 모두 드랍 후 다시 생성.

conf에 시큐리티 주석 해제.

restart.

해결.

 

 

과정 : 

mongod root로 접속 후, use admin, createUser로 로그인 계정 생성.

그 후 각각 디비 생성, 해당 디비에 접속할 권한을 가진 유저들을 세팅.

디비명, 아이디, 비밀번호에 뭔 오타가 있는지 접근 안되고 유저를 찾을 수 없다고 뜸.

근데 아무생각없이 유저를 지운다는걸 디비를 지워버림

UserNotFound: Could not find user "root" for db "admin"

[thread1] Error: Authentication failed. :

그래서 뜬 에러.

 

 

 

1. mongod.conf에서 시큐리티 해제.

// /etc/mongod.conf 내 security 주석처리. 아랫줄은 스페이스 2칸.
#security:
#  authorization: enabled

 

 

2. mongod 들어가서 세팅.

// root로 접속
su
mongod

// 재생된 admin 사용
use admin

// 유저 생성, userAdminAnyDatabase roles로.
# roles = privileges
# root ~ userAdminAnyDatabase ~ dbAdminAnyDatabase
# 셋 공통) 루트 권한에 준함, All-Database Roles
# 셋 차이)
# privileges range) root > dbAdmin > userAdmin
# dbAdmin – Grant privileges to perform administrative tasks
# userAdmin – Allows you to create and modify users and roles on the current database

// 해당 계정으로 로그인 --authenticationDatabase admin 추가해서.
(1) 해결.

 

 

3. 디비 있는거에 전부 들어가서 유저 삭제. 디비도 삭제

// 디비에 들어가 계정 삭제
Use db_name;
show users;
db.dropUser("user_name");

// 들어가 있는 디비 삭제
db.dropDatabase();

 

4. conf에 시큐리티 주석 해제.

 

5. systemctl restart mongod

 

끝.

728x90