본문 바로가기

Ubuntu

SSH 접속하기

Server의 IP주소는 다음과 같다.

$ hostname -I
192.168.0.39  192.168.1.2

IP주소가 두개가 나오는 이유는 랜카드가 두개라서 그렇다.

 

SSH접속은 다음과 같이 한다.

ssh USERNAME@IP ADRESS

라우터를 통한 연결

ssh dell@192.168.0.39
The authenticity of host '192.168.0.39 (192.168.0.39)' can't be established.
ED25519 key fingerprint is SHA256:Pf+YFT2P9zVjt2ctSIrMYGqHdNkc7Ovfl0bx9q77ZcE.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.39' (ED25519) to the list of known hosts.
dell@192.168.0.39's password: 
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-26-generic x86_64)

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

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

12 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Last login: Wed Aug 23 12:34:39 2023 from 192.168.1.1

다이렉트 연결

ssh dell@192.168.1.2
The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
ED25519 key fingerprint is SHA256:Pf+YFT2P9zVjt2ctSIrMYGqHdNkc7Ovfl0bx9q77ZcE.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.2' (ED25519) to the list of known hosts.
dell@192.168.1.2's password: 
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-26-generic x86_64)

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

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

12 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

이제 맥으로 접속해보면, 문제가 생겼다. 동일 IP에 우분투 재설치를 해서 그렇다. 왜냐하면 최근 접속을 기억하고 있으니까.

ssh dell@192.168.0.39
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:Pf+YFT2P9zVjt2ctSIrMYGqHdNkc7Ovfl0bx9q77ZcE.
Please contact your system administrator.
Add correct host key in /Users/jinsunlee/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/jinsunlee/.ssh/known_hosts:4
Host key for 192.168.0.39 has changed and you have requested strict checking.
Host key verification failed.

맥에서 /Users/jinsunlee/.ssh/known_hosts 파일을 보도록 하자. 숨김 파일이니까 Shift + command + .

[192.168.0.10]:3861 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEqeuGOPVH4agbGmUkp8mzYz+JBCoQL+BcEhxS8c5FF6
192.168.0.39 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL+X2WU4P3ky8nY5F+W2Ekc8UVXVfzz3Lwp34Rzl5FDE
192.168.0.39 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4L7zzCCCihBT3m2JhHi2jEjR+cXvlrQrNHsGqHkZ8qRoQKJpCyWxL1qmprpa/H0lSwOAo2nZctbCsWNPo4B9n8fAxoqmVj74gVqf1HNFugwmpF4cfcS7Jx0TO2fQ3H8jbFONAGKht+6QLXlvAcRbgmqCenLkmkVrqyUhw5mYSjIWmN1tCvvUzHvzepX6Of+xxJrMd6iOO4kfKz0RsM/Bv3lwq4u3QsF5pW+fHa5cA0CqE+KKHf3KIR6wU9tCWSbDqpZcjeovuLnOOGkK0A2qa5ZXlbX1ii/mBN0XD0Ckwr6wb1EjQigDR0tCTsvywO91ac6v2Ymv4HbxffTYxY6e1nHtK/oTnyPnbYElJsdKYttgpRBTdsLJlTUURVn7YURjceweqMkMDHeUhTM7buUPW4NTCQU0ZlGf1MGk4KwA4SqyNYUka/za0tYJ1Gc9hbWnAa6YM0rLn9f2akBw0DHvFBQpbKsjz3RM3GzTeE0T4dHTr3yIGV0Vaplz9Ap8rhLs=
192.168.0.39 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAkWr2tRox0Zl3GtCGZW0n+6FE+ILOzydfv4EfczU62rhEKI9lsGF9cmekU11T0bh+4RSd9NQcWaSD5xb825rJM=

예전 접속시 만들어진 key가 존재한다. known_hosts 파일 안에 내용을 싹 지우고 다시시도.

ssh dell@192.168.0.39
The authenticity of host '192.168.0.39 (192.168.0.39)' can't be established.
ED25519 key fingerprint is SHA256:Pf+YFT2P9zVjt2ctSIrMYGqHdNkc7Ovfl0bx9q77ZcE.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.39' (ED25519) to the list of known hosts.
dell@192.168.0.39's password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-26-generic x86_64)

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

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

12 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Last login: Wed Aug 23 12:38:19 2023 from 192.168.0.4

된다. 이번에는 외부 IP를 통한 접속을 해보자.

ssh dell@61.245.224.8 -p 42970
ssh: connect to host 61.245.224.8 port 42970: Connection refused

Port forwarding 문제가 발생하였다.

공유기에서 TCP로 Port forwarding을 설정해 주고, 서버의 /etc/ssh/sshd_config 파일을 바꾸어 준다.

#Port 22

Port XXXX
ssh dell@61.245.224.8 -p 42970
The authenticity of host '[61.245.224.8]:42970 ([61.245.224.8]:42970)' can't be established.
ED25519 key fingerprint is SHA256:Pf+YFT2P9zVjt2ctSIrMYGqHdNkc7Ovfl0bx9q77ZcE.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: 192.168.0.39
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[61.245.224.8]:42970' (ED25519) to the list of known hosts.
dell@61.245.224.8's password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-26-generic x86_64)

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

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

12 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Last login: Wed Aug 23 12:52:49 2023 from 192.168.0.11

'Ubuntu' 카테고리의 다른 글

우분투 파일, 디렉토리 권한 확인  (0) 2023.08.23
계정 확인 방법  (0) 2023.08.23
Linux (Ubuntu) PC2대 클러스터링  (0) 2023.08.23
gcc vs gcc-base  (0) 2023.08.13
APT vs PPA  (0) 2023.08.13