> For the complete documentation index, see [llms.txt](https://ellerymoon.gitbook.io/study-archive/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ellerymoon.gitbook.io/study-archive/etc/undefined/ec2-ssh-connection.md).

# EC2 ssh connection 쉽게 하기

원래 방식은 이 방식으로 해야됨. 귀찮다

```
$ ssh -i {YOUR_KEY_PAIR_FILE.pem} {USER_NAME}@{AWS_PUBLIC_DNS_}
```

본인이 지정한 alias만 입력해서 접속하는 방식으로.  `$ssh {alias} 로 접속하게 만들자`

1. pem 키를 `~/.ssh` 경로에 복사한다 ( 이후 ssh 실행 시에 pem키를 자동으로 읽어서 접속을 진행함)

`cp {pem 키 위치} ~/.ssh`

2. pem 키 권한 변경

`chmod 600 ~/.ssh/{pem키 이름}`

3. `~/.ssh` 경로에 config파일 생성

`vim ~/.ssh/config`

```
Host {alias로 쓸 서비스 명칭}
    HostName {ec2 EIP 주소}
    User ec2-user
    IdentityFile ~/.ssh/{pem키 이름}
```

4. config 파일에 실행권한 설정

`chmod 700 ~/.ssh/config`

5. `ssh {alias}` 으로 접속할 수 있다
