본문 바로가기
Project/3-Tier Architecture

[3-Tier] AWS WAS EC2 생성 후 Bastion Host에서 SSH 접속하기 (WAS 서버 구성1)

by ganyga 2024. 2. 22.

WAS EC2 생성하기

OS : Amazon Linux 2

인스턴스 유형 : t2.micro

네트워크 설정

  • VPC : Ga-VPC
  • Subnet : Ga-WAS-Pri-A
  • 퍼블릭 IP 자동 할당 : 비활성화 (Private Subnet 이므로)
  • 보안 그룹 생성 : Ga-WAS-A-SG


보안 그룹 설정(WAS-SG)

인바운드 규칙 편집(Bastion 사설 IP SSH 허용, Bastion Host → WAS 접근하기 위해서)


Bastion Host → WAS EC2 SSH 접속하기

Bastion Host에 WAS Keypair 옮기기

SCP 명령어) local(로컬) → remote(원격지)

scp -i [접속할 Keypair][옮길 Keypair][사용자 ID] @ [접속할 IP]:[경로]

scp -i Ga-Bastion.pem Ga-WAS.pem ec2-user@52.79.253.139:/home/ec2-user
Ga-WAS.pem                                  100% 1674   100.4KB/s   00:00

 

Bastion Host에서 Keypair 옮겨진 거 확인하고 chmod 400 권한 주기

# WAS Keypair 옮겨진 거 확인
[root@bastion ec2-user]# ls
Ga-WAS.pem  Ga-WEB.pem  keypair

# chmod 400 권한 주기 전
[root@bastion ec2-user]# ll
total 8
-rw-r--r-- 1 ec2-user ec2-user 1674 Jan 20 02:38 Ga-WAS.pem
-r-------- 1 ec2-user ec2-user 1674 Jan 20 01:56 Ga-WEB.pem
drwxr-xr-x 2 root     root        6 Jan 20 01:45 keypair

# chmod 400 권한 준 후
[root@bastion ec2-user]# chmod 400 Ga-WAS.pem
[root@bastion ec2-user]# ll
total 8
-r-------- 1 ec2-user ec2-user 1674 Jan 20 02:38 Ga-WAS.pem
-r-------- 1 ec2-user ec2-user 1674 Jan 20 01:56 Ga-WEB.pem
drwxr-xr-x 2 root     root        6 Jan 20 01:45 keypair

 

Bastion Host → WAS EC2 SSH 접속

[root@bastion ec2-user]# ssh -i "Ga-WAS.pem" ec2-user@10.100.3.16

The authenticity of host '10.100.3.16 (10.100.3.16)' can't be established.
ECDSA key fingerprint is SHA256:1+PL5qo+z9EqQno08U8+9fbMU9dwrL1eKyiK1baGUU8.
ECDSA key fingerprint is MD5:ed:25:f5:50:fc:39:b1:26:ee:f5:fe:3d:cd:69:74:4e.
Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '10.100.3.16' (ECDSA) to the list of known hosts.
   ,     #_
   ~\_  ####_        Amazon Linux 2
  ~~  \_#####\
  ~~     \###|       AL2 End of Life is 2025-06-30.
  ~~       \#/ ___
   ~~       V~' '->
    ~~~         /    A newer version of Amazon Linux is available!
      ~~._.   _/
         _/ _/       Amazon Linux 2023, GA and supported until 2028-03-15.
       _/m/'           https://aws.amazon.com/linux/amazon-linux-2023/
       

[ec2-user@ip-10-100-3-16 ~]$

 

hostname 변경하기

hostnamectl set-hostname [변경할 이름]

[ec2-user@ip-10-100-3-16 ~]$ sudo su -

# hostname 변경
[root@ip-10-100-3-16 ~]# hostnamectl set-hostname was-a

# 적용
[root@ip-10-100-3-16 ~]# su 

# 확인
[root@was-a ~]# hostname
was-a