다가오는 다음을 향해

[VPS hostinger] SSH Key 발급 및 SSH key 로 VPS 접속 방법 본문

Server/VPS(hostinger)

[VPS hostinger] SSH Key 발급 및 SSH key 로 VPS 접속 방법

hyeseo 2024. 1. 2. 14:02

SSH Key

💡 SSH Key 발급 및 SSH key 로 VPS 접속 방법 안내

 

1. known_hosts 파일 삭제

rm ~/.ssh/known_hosts

 

2. ssh 접속

ssh ****@**.**.***.***

 

3. 아래 내용이 나오면 yes 입력

The authenticity of host '**.**.***.*** (**.**.***.***)' can't be established.
ED25519 key fingerprint is SHA256:****.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

 

4. root 비밀번호 입력

Warning: Permanently added '**.**.***.***' (ED25519) to the list of known hosts.
root@**.**.***.***'s password:

 

5. 접속 후 exit로 종료

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-1040-kvm x86_64)

 * Documentation:  <https://help.ubuntu.com>
 * Management:     <https://landscape.canonical.com>
 * Support:        <https://ubuntu.com/advantage>

  System information as of Tue Sep 12 05:14:13 UTC 2023

  System load:  0.0               Processes:             72
  Usage of /:   3.5% of 48.27GB   Users logged in:       0
  Memory usage: 3%                IPv4 address for eth0: **.**.***.***
  Swap usage:   0%                IPv6 address for eth0: ***:4780:10:c9ea::1

...

root@srv418991:~# exit

 

6. ssh key를 생성할 디렉토리로 이동

cd ~/.ssh/keys

# keys 라는 디렉토리를 생성은 필수는 아니나 똑같이 생성하고 싶다면 아래 명령어로 생성
mkdir keys

#현재 디렉토리의 목록을 확인
ls - Mac
ll - Window

#keys 디렉토리로 이동
cd keys

 

7. keygen으로 ssh key 생성

ssh-keygen -t ed25519

 

8. key name 입력 (ex: dev-sckey)

Generating public/private ed**** key pair.
Enter file in which to save the key (/Users/****/.ssh/id_ed****):

 

9. 비밀번호 없이 로그인 하기 위해 Enter만 입력

Enter passphrase (empty for no passphrase):
Enter same passphrase again

 

- 발급 성공 로그

Your identification has been saved in dev-sckey
Your public key has been saved in dev-sckey.pub
The key fingerprint is:
SHA256:***
The key's randomart image is:
+--[ED25519 256]--+
|     +.==o=.+.o  |
|      B.oo = * . |
|       o..o * .  |
|       . + . +.  |
|    . . S   B. . |
|     o . o o.B.o |
|      . +  . .O  |
|     . .  .  o.. |
|     .o    .E.+o |
+----[SHA256]-----+

 

10. ssh key 가 생성되었는지 확인

# 목록 확인 명령어

ls - Mac
ll - Window

$ dev-sckey     dev-sckey.pub

 

11. public 키를 서버로 복사: public, private 키 쌍으로 인증할 수 있게 됩니다.

ssh-copy-id -i dev-sckey.pub root@**.**.***.***

 

12. ssh key 로 접속 확인

# ssh key가 저장된 디렉토리에서 실행
ssh -i dev-sckey root@**.**.***.***