Linux 일반 계정으로 sudo 명령어가 안될 때 or 패스워드 입력없이 실행하고 싶은 경우

[ 문제 상황 ]

 

1. Oracle Linux oracle 계정으로 설치된 패키지 조회해보기 ( RHEL 기반이므로 Yum 이용 )
   : sodoers.file에 oracle 계정이 없다는 에러 발생

[oracle@ol7s19c ~]$ sudo yum list installed
 
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for oracle:
oracle is not in the sudoers file.  This incident will be reported.

 


2. yum Install 해보기
   : superuser 권한으로 가능하다고 에러

[oracle@ol7s19c ~]$ yum install figlet
Error: This command has to be run with superuser privileges (under the root user on most systems).

   


3. superuser privilege를 잠시 빌려오는 sudo 명령문 이용

[oracle@ol7s19c ~]$ sudo yum install figlet
[sudo] password for oracle:
oracle is not in the sudoers file.  This incident will be reported.

^^ ;; 지속적으로 보이는 에러 내용 "sudoers file" 

※ sudoers 파일은 무엇일까?
  : sudo 명령어를 통해 특정 사용자나 그룹에게 시스템 관리 명령을 실행할 수 있는 권한을 부여하는 설정 파일.
  
※ sudo는 무엇일까?
  : sudo는 Unix 및 Linux 시스템에서 관리자 권한(루트 권한)을 임시로 부여받아 명령을 실행할 수 있게 해주는 명령어.
    이는 사용자가 시스템 전체의 관리 작업을 수행할 때, 루트 계정으로 직접 로그인하지 않고도 필요한 권한을 얻을 수 있게 해줌. 
    sudo는 특정 명령어에 대해서만 권한을 부여함으로써 보안을 유지하는 데 중요한 역할.

 

 

[ 해결 방안 ]

  : sudoers file에 계정을 등록해야 sudo 명령문을 사용할수 있기 때문에 파일에 oracle 계정을 등록하자.   


1. root 접속 아래 실행 ( sodoers.file open ) 

[root@ol7s19c ~]# sudo visudo

※ visudo는 무엇일까?   
   Unix 및 Linux 시스템에서 sudoers 파일을 안전하게 편집하기 위한 명령어.

 

2. 열린 sodoer.file 하단에 보면, 아래 문구를 찾아 oracle 줄을 입력한다.
   입력한 목적은 oracle 계정으로 yum 명령문을 패스워드 입력없이 실행하겠다는 것 ( sudo 명령문을 쓸수 있으나, yum에 한정 )

1) oracle 계정에서 패스워드 입력없이 sudo 실행 되도록 설정 

[root@ol7s19c ~]# sudo visudo

## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
oracle  ALL=(ALL) NOPASSWD: /usr/bin/yum
[oracle@ol7s19c ~]$ sudo yum install figlet
Last metadata expiration check: 0:48:36 ago on Thu 13 Jun 2024 04:10:11 PM KST.
Package figlet-2.2.5-18.20151018gita565ae1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

2) oracle 계정에서 패스워드 입력하여 sudo 실행 되도록 설정 ( NOPASSWD : 제거 ) 

[root@ol7s19c ~]# sudo visudo

oracle  ALL=(ALL) /usr/bin/yum
[oracle@ol7s19c ~]$ sudo yum install figlet
[sudo] password for oracle:
Last metadata expiration check: 1:14:50 ago on Thu 13 Jun 2024 04:10:11 PM KST.
Package figlet-2.2.5-18.20151018gita565ae1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

 

3. 테스트 서버이니, yum 뿐만 아니라 모든 명령문을 편하게 쓰고 싶을때는 ALL 입력

[root@ol7s19c ~]# sudo visudo

oracle  ALL=(ALL) NOPASSWD: ALL