infra/etc

[CentOS] sudo가 안될때 - sudoers 추가 하기

hjhello423 2019. 10. 10. 21:42

centos를 처음 설치하고 yum 업데이트를 실행하려는데..

itsme is not in the sudoers file.  This incident will be reported.

이런 문구가 나왔다.

 

CentOS에서는 기본적으로 일반 유저가 sudo 명령어를 사용 불가능하다.

[itsme@localhost ~]$ sudo yum -y update 
[sudo] password for itsme: 
itsme is not in the sudoers file.  This incident will be reported.

 

뭔가 하고 찾아보니 sudoers에 로그인한 유저를 추가해 주어야 한다고 한다.

 

방법은 두 가지가 있다.

1. /etc/sudoers에 유저 추가 하기.

2. sudo 그룹에 유저 추가 하기.

 


먼저 첫 번째 방법이다.

일단 root계정으로 접근해야 한다. su 명령어를 이용해 root로 로그인 하자.

[itsme@localhost ~]$ su -
Password:
[root@localhost ~]#

그리고 /etc/sudoers 파일을 변경해 주자.

itsme 계정에 sudo 권한을 주려고 한다.

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
itsme   ALL=(ALL)       ALL

 

자 변경되었다면 사용하면 된다!

하지만 나는 변경 실패했다. ㅎㅎ

변경하려고 했더니 readonly 파일이란다.

파일 퍼미션을 변경해서 수정 가능하도록 해보자

[root@localhost ~]# ls -al /etc/sudoers
-r--r-----. 1 root root 4348 Oct 10 21:58 /etc/sudoers

[root@localhost ~]# chmod 660 /etc/sudoers
[root@localhost ~]# ls -al /etc/sudoers
-rw-rw----. 1 root root 4348 Oct 10 21:58 /etc/sudoers

 

이제 수정 가능하게 되었다.

다시 vi를 이용해 파일을 수정해 보자.

수정한 뒤에는 반드시 원래 퍼미션으로 돌려두는 걸 잊지 말자.

[root@localhost ~]# chmod 440 /etc/sudoers
[root@localhost ~]# ls -al /etc/sudoers
-r--r-----. 1 root root 4348 Oct 10 21:58 /etc/sudoers

 

이제 완료됐다.

exit를 이용해 다시 원래 계정으로 돌아 간 후 sudo 명령어를 사용해 보자.

 

 

반응형