작업을 하다 보면 root 권한이 아닌 계정에 root 권한이 필요한 명령어를 실행해야 할 때가 많습니다.
sudo 권한을 설정하는 설정 파일에서 설정하면 되는데, 자꾸 잊어버려 기록합니다.
우선 root 계정으로 접속하여 아래 명령어를 입력하여 해당 경로로 이동합니다.
vi /etc/sudoers
그럼 다음과 같은 파일이 보이는데
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults env_keep += "HOME"
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
test ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
21번째 줄에 ## Allow root to run any commands anywhere라는 부분이 있는데 이 아래에 있는 내용이 바로 root 권한을 설정해 주는 부분입니다. (실제 파일에선 99번째 줄입니다.)
저는 계정이름이 test이기 때문에 아래와 같이 입력하였습니다.
test ALL=(ALL) ALL
저장하고 나와줍니다. 이후에 sudo 명령어를 이용할 수 있습니다.
번외로 sudoers 파일은 권한에 관련된 아주 중요한 파일이기 때문에 보통 쓰기 권한이 없습니다.
따라서 쓰기 권한을 주고 해당 부분을 편집하시면 됩니다.
쓰기 권한은 다음 명령어로 설정할 수 있습니다.
//쓰기권한 주기
chmod +w sudoers
//쓰기권한 제거
chmod -w sudoers
작업을 모두 마치고나면 꼭 쓰기 권한을 다시 없애주시면 됩니다.
'개발' 카테고리의 다른 글
[Java/자바] JPA 에 대하여 (1) - JPA의 등장 (0) | 2024.10.26 |
---|---|
[CI/CD] GitHub와 Jenkins를 이용한 배포 자동화 구축하기 (0) | 2024.10.23 |
node.js 실행파일 만들기 (2) | 2023.07.14 |
[CentOS 7/Linux]리눅스 MariaDB 바이너리 파일로 설치하기(yum없이 tar.gz이용) (10) | 2023.03.30 |
VMware 우분투 설치하기(가상머신 : Ubuntu22.04) (0) | 2023.03.06 |