본문 바로가기
AWS/EC2

[AWS] EC2 Root Login 구성하기(Amazon Linux)

by study4me 2024. 10. 10.
반응형

기본적으로 AWS EC2는 Root 접속을 차단한다.
EC2에서 Root 접속이 필요할 경우 아래와 같이 구성할 수 있다.

1. Root User로 Switch

sudo su -

2. PermitRootLogin 옵션 수정

vi /etc/ssh/sshd_config

# 다음 옵션 값 수정 후 저장
PermitRootLogin yes
# sshd 재기동
service sshd restart

3. Please login as the user rather than the user "root" 문제 해결

이 상태에서 Pem Key를 사용하여 root로 접속하려고하면 아래와 같이 나온다.

Please login as the user "ubuntu" rather than the user "root".
Please login as the user "ec2-user" rather than the user "root".

vi /root/.ssh/authorized_keys
아래와 같이 앞부분을 제거 후 저장한다.

# 수정 전
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10;exit 142" ssh-rsa AAAAB3NzaC1yc2EAAAADAQA......(생략)......LUT key-name-example


# 수정 후
ssh-rsa AAAAB3NzaC1yc2EAAAADAQA......(생략)......LUT key-name-example

이제 Pem Key를 사용하여 Root login이 가능하다.

 

별첨. Password 방식으로 root 원격 접속을 하고 싶다면?

vi /etc/ssh/sshd_config

# 다음 옵션 값 수정 후 저장
PasswordAuthentication yes
# sshd 재기동
service sshd restart

위와 같이 Password로 접속 가능하도록 설정 후 로그인을 시도해본다.
만약 Password로 로그인을 시도했을 때 Permission denied (publickey). 에러가 발생한다면 다음 설정도 진행해준다.

vi /etc/ssh/sshd_config

# 다음 옵션 값 수정 후 저장
KbdInteractiveAuthentication yes

KbdInteractiveAuthentication

Keyboard-Interactive Authentication란 의미로 SSH(Secure Shell) 프로토콜에서 사용되는 인증 방법 중 하나다.
이 방법은 사용자와 서버 간의 상호작용을 통해 인증을 수행한다.
SSH 클라이언트와 서버가 서로 질문과 답변을 주고받는 방식으로, 주로 다단계 인증이나 추가적인 보안 질문을 처리하는 데 사용된다.

반응형

'AWS > EC2' 카테고리의 다른 글

[AWS] EBS Mount하는 방법 in Linux  (0) 2021.03.31