IT/보안

[보안점검] root 계정 원격 접속 제한

송시 2022. 5. 10. 14:48
728x90

UNIX/LINUX 에서 root 권한을 갖고 있다는 의미는 그 시스템에서 할 수 있는 모든 것이 가능하다는 의미이기도 하다.

 

대부분 별로 관심없겠지만, 원격에서 여러 형태의 무차별대입 공격이 많이 있고, 그 중 비밀번호를 무차별로 대입하여 공격하는 형태의 자동화 공격이 시도 때도 없이 존재 한다.

 

보안측면에서 본다면 방화벽, SSL VPN 이나 NAT를 사용하는 것이 최고지만 모든 환경에서 SSL VPN 을 사용할 수 있는 것은 아니다.(도입 비용 및 유지보수 등이 이 최고의 것을 선택할 수 없는 이유일 수도)

 

어쨌든 저런 것이 없는 상태라고 가정하고 시스템에서만 할 수 있는 최고의 방법은

 

원격에 대한 접근을 적절하게 차단하는 것이 아닐까.

 

그중 가장 많이 사용하는 sshd 로만 본다면

 

/etc/ssh/sshd_config 파일에서

 

PermitRootLogin no 설정을 통해 root 계정이 원격으로부터 접근 하는 것을 막을 수 있게 된다.

 

추가로 터미널 자체를 제어할 수가 있는데

 

/etc/securetty 파일에 대해서 man 페이지를 간략하게 살펴본다면

 

"securetty - file which lists terminals from which root can log in" 루트가 터미널에 로그인 할 수 있는 터미널의 목록이 열거 되어 있는 파일이다.

 

이곳에 원격접속시에 사용하는 pts 부분을 삭제한다면 원격을 통한 터미널 접속을 막을 수 있게 된다.

 

검사 방법은 아래의 방법을 사용 가능하고

 

# grep ^PermitRootLogin[[:space:]]*no /etc/ssh/sshd_config

 

두번째가 정확하게 검사에 도움이 되겠고 출력된다면 ssh 접근에 대해 root 권한을 잘 막은 것이고, 출력이 안된다면 root 로 접속이 가능하게 된다.

 

만약 PermitRootLogin 이 주석처리되어 있다면 기본적으로 yes 가 적용되어 root 권한으로 접속이 된다.

 

root 권한 접속 허용과 관계 없이, 무차별 공격 자체를 막아주는 것은 아니기에 원격접속이라는 것 자체를 가급적 외부에 노출되지 않는 여러 다양한 방법들을 고민해봐야 한다.

 

** /etc/securetty 는 setup package 에 들어있는 파일인데, centos8 stream 최신버전에서 securetty 파일이 setup 패키지에서 빠졌다. 

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/considerations_in_adopting_rhel_8/index#securetty_security

 

Considerations in adopting RHEL 8 Red Hat Enterprise Linux 8 | Red Hat Customer Portal

This document provides an overview of changes in Red Hat Enterprise Linux 8 since Red Hat Enterprise Linux 7 to help you evaluate an upgrade to Red Hat Enterprise Linux 8.

access.redhat.com

8.7.2. securetty is now disabled by default

Because of the dynamic nature of tty device files on modern Linux systems, the securetty PAM module has been disabled by default and the /etc/securetty configuration file is no longer included in RHEL. Since /etc/securetty listed many possible devices so that the practical effect in most cases was to allow by default, this change has only a minor impact. However, if you use a more restrictive configuration, you need to add a line enabling the pam_securetty.so module to the appropriate files in the /etc/pam.d directory, and create a new /etc/securetty file.

728x90