오류 원인, 해결
mac 터미널로 EC2에 접속하려고 했으나.. 자꾸 오류가 떴다.
오류는 .ssh 파일에 안 들어가지는 것!!!!
cd: not a directory: ~/.ssh
구글링을 해보니 ssh 키가 생성이 안되었다면 파일이 없을 수 있다는 것이었다.
그래서 파일을 생성해보려해도..
mkdir: ~/.ssh: File exists
파일이 이미 존재한다는 것..!
도대체 파일이 존재하는데 왜 안들어가지고 파일을 수정할 수도 없는 거지..?라고 생각하고,
ssh 키를 생성하려고 하자 내가 만날 수 있는 모든 에러를 맞닥뜨리고 난 뒤..
.ssh 파일을 지워버리기로 결정했다.
다시 .ssh 파일을 생성하고 보니까 생성된 파일은 실행파일이 아니었던 것이다..
지금까지 Unix 실행 파일 가지고 이리저리 해보니 어떤 거에서든 에러를 마주쳤던 것..!!!
다행히도 .ssh 파일을 생성해 준 후 구글링을 통해 ssh 키를 발급하고, 접속하는 것까지 모두 성공했다.
그렇다면 .ssh Unix 실행파일은 무엇인가?
살펴보니 내가 발급받았던 .pem 파일을 .ssh에 복사할 때 생긴 파일인 것 같다.
왜냐하면, .pem에 있는 키가 모두 똑같았다..!
정리하자면,
1. 컴퓨터에는 .ssh 파일이 없었음
2. ssh에 간편히 접속하기 위해 .pem파일을 .ssh파일에 복사함
3. 단순히 내용을 그대로 복사한 .ssh 파일이 생성됨
4. 이 Unix 실행파일이 구글링 하였을때 나오는 .ssh 파일인 줄 착각하고 에러를 맞닥뜨리기 시작..
결과적으로 .ssh 파일이 생성되어 있는지 확인을 하지 못한 채 파일을 복사한 것이었다.
다음부턴 제대로 확인해야겠다!
SSH란?
SSH는 Secure Shell로, 원격 호스트에 접속하기 위해 사용되는 보안 프로토콜이다.
*Shell: 명령어와 프로그램을 사용할 때 쓰는 인터페이스
SSH 사용 이유
원격 접속을 위해 WireShark 같은 패킷 분석 프로그램을 이용하면, 원격 접속 과정에서 옮겨지는 비밀번호나 파일 내용 등의 데이터를 탈취할 수 있다.
때문에 이를 암호화하는 SSH 기술이 등장하였고, 현재 원격 접속 보안을 위한 필수적인 요소이다!
또한 AWS같은 클라우드 서비스에서 제공하는 서버는 기본적으로 원격 접속을 해서 접근해야한다.
따라서 AWS에서 서버 생성시 필수적으로 SSH 보안 과정을 거치며, 나 또한 AWS를 통해 SSH에 접하게 되었다.
SSH 작동 원리
가장 중요한 키워드가 바로 "키"이다.
사용자(클라이언트)와 서버(호스트)는 각각의 키를 보유하고 있으며, 이 키를 이용해 연결 상대를 인증하고 데이터를 주고받는다.
이때 키를 생성하는 방식으로 "대칭키"와 "비대칭키(공개키)"가 있다.
비대칭키
최초 접속 시 사용자와 서버 간의 인증 절차가 비대칭키 방싱을 통해 완료된다.
먼저, 사용자 또는 서버가 키 페어를 생성한다. 키 페어를 생성하면 공개키와 개인키가 생기는데, 개인키는 서버 생성 시에 제공받았던 pem 파일이 바로 그 개인키이다.
공개 키는 서버에 전송하여, 개인 키를 가지고 있는 사용자와 서버의 공개 키 값을 비교하여 올바른 개인 키를 보유하고 있다면 접속을 허용해 준다.
키 페어: 공개 키(.pem)와 개인 키의 두 가지로 이루어진 한 쌍
대칭키
이제 정보를 주고받는 과정에서 정보가 새어나가지 않기 위해 정보를 암호화해서 주고받는데, 여기서 사용되는 과정이 대칭키 방식이다.
대칭키 방식에서는 사용자와 서버가 한 개의 키만 사용한다.
공유된 대칭 키를 이용해 정보를 암호화하면, 받은 쪽에서 동일한 대칭 키로 복호화하여 정보를 습득하게 된다.
접속할때마다 새로운 대칭 키가 생성되며, 교환이 완료되면 키는 폐기된다.
틀린 부분이 있다면 지적해주시면 감사하겠습니다.
Reference
'Server' 카테고리의 다른 글
[tomcat] welcome-file 안 열림 오류 해결 (0) | 2024.09.24 |
---|---|
[Tomcat] The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 404 에러 해결 (0) | 2024.09.23 |
[JPA] 기본키 생성 전략 / @GeneratedValue (0) | 2024.08.25 |
[JPA] 영속성 컨텍스트 #2 (0) | 2024.08.08 |
[SpringBoot] Entity 생성하기 / JPA 간단한 예제 (0) | 2024.08.07 |