[CentOS 7] /bin/bash Permission deny after yum update then reboot
Cause
Selinux disable 상태로 사용하다가, Yum update를 할 경우, selinux 설정 파일(/etc/selinux/config)이 초기화되는 경우가 있습니다.
초기화되면 아래와 같이 disabled → enforcing 즉, reboot 시 다시 활성화하도록 바뀝니다.
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
이 경우, 이 상태로 reboot를 진행하면, console login이 되지 않으며, ssh로 접속 시 /bin/bash Permission deny를 내뱉으며 prompt로 진입이 되지 않게 될 수 있습니다.
Solution
1. 안전(Single) 모드 콘솔 부팅: 아래 화면에서 키보드 'e'를 누릅니다.
2. 화면 아래쪽으로 내리면, 캡쳐 화면의 노란색 부분이 나옵니다.
3. “ro” → “rw”로, “rhgb quiet” → “init=/bin/bash” 로 편집한 뒤, Ctrl+x를 눌러 single mode 진입 시작합니다.
4. 아래와 같이 .autorelabel
을 만들어주고, exec /sbin/init
을 실행하면, selinux가 다시 레이블링을 하게 되며, 정상적으로 부팅 및 로그인 될 것 입니다.
Root password 분실 등과 같은 문제도, 위와 같이 Single mode 진입하여 passwd 명령을 통해 재설정 할 수 있습니다.
Post-prevention
제품 혹은 개발 테스트를 위해 Selinux를 해제해야 할 경우,$ setenforce 0
(즉, permissive mode) 명령을 사용하여 임시 해제하는 것을 권장합니다.
만일, 일정 기간 reboot 후에도 permissive되기를 원한다면,
/etc/selinux/config의 SELINUX=enforcing
를 disabled
대신 permissive
로 설정합니다.
또한 만일, disabled
로 할 경우, 다시 enforcing
모드로 진입하기 위해서는 .autorelabel 파일을 만들 후, reboot해야 합니다.