리눅스 sudo 패스워드 없이 사용

Linux sudo 패스워드 없이 사용
sudo 패스워드 없이 사용

1 방법

사용자명 ALL=NOPASSWD: ALL
→ 여기서 NOPASSWD:를 빼면 sudo 실행시 자신의 패스워드를 입력해야만 함
사용자명 ALL=NOPASSWD: 명령어1, 명령어2
→ 지정한 명령어들만 sudo 사용가능

2 실습 1: 모든 명령어 사용가능

  • 신규 계정 testuser1 생성
[root@shelltest ~]# useradd testuser1 -p 'P@ssw0rd1'
[root@shelltest ~]# cat /etc/passwd | grep testuser1
testuser1:x:500:500::/home/testuser1:/bin/bash
  • testuser1 sudo 권한 추가(+NOPASSWD)
[root@shelltest ~]# echo 'testuser1 ALL=NOPASSWD: ALL' >> /etc/sudoers
[root@shelltest ~]# cat /etc/sudoers | tail -2
#includedir /etc/sudoers.d
testuser1 ALL=NOPASSWD: ALL
  • testuser1에서 sudo 권한 실행
[root@shelltest ~]# su - testuser1
[testuser1@shelltest ~]$ reboot
reboot: Need to be root
[testuser1@shelltest ~]$ sudo reboot
The system is going down for reboot NOW!

3 실습 2: 지정한 명령어만 사용가능

[root@localhost ~]# vi /etc/sudoers
변경 전
#includedir /etc/sudoers.d
testuser1 ALL=NOPASSWD: ALL
변경 후
#includedir /etc/sudoers.d
testuser1 ALL=NOPASSWD:/usr/sbin/httpd, /etc/rc.d/init.d/mysqld

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}