[ssh] 다른 ssh 서버를 거쳐 접속할 때, ProxyJump

ssh 서버 A를 거쳐 ssh 서버 B를 접속하고 싶다면 다음과 같이 ~/.ssh/configProxyJump 를 쓰면 ssh b.dasomoli.org 명령으로 바로 접근하는 것처럼 쓸 수 있다.

Host a.dasomoli.org 11.22.33.44
    Hostname 11.22.33.44
    User dasomoli
    IdentityFile ~/.ssh/a.dasomoli.org.pem

Host b.dasomoli.org 11.22.33.55
    Hostname 11.22.33.55
    User dasomoli
    IdentityFile ~/.ssh/b.dasomoli.org.pem
    ProxyJump dasomoli@a.dasomoli.org

[ssh] config 파일에 IP와 Hostname을 함께 지정

~/.ssh/config 파일 안에 hostname을 지정한다면, 그 뒤에 IP 주소를 함께 지정하면 hostname이나 IP 둘 중 어느 하나로 접속해도 같은 설정이 적용된다. 항목을 여러개 만들 필요 없다. 공백으로 구분하면 다 같이 적용된다. 예를 들면 다음과 같다.

Host nas.dasomoli.org 112.145.250.152 192.168.0.204
    HostName nas.dasomoli.org
    User dasomoli
    Port 2048
    IdentityFile ~/.ssh/id_rsa_dasomoli_nas

SSH 접속 password 입력없이 RSA키로 접속하기

ssh 접속할 때마다 password 치기가 귀찮다…

클라이언트에서 키 생성

$ ssh-keygen -t rsa -N '' -q -f ~/.ssh/id_rsa

접속하려는 서버로 공개키 복사.

$ ssh-copy-id <account>@<server hostname>

위의 복사는 아래와 동등하다. 위 명령을 했다면 아래를 할 필요는 없음.

$ scp ~/.ssh/id_rsa.pub <account>@<server hostname>:.ssh/authorized_keys

예를 들면 다음과 같이 한다.

ssh-keygen -t rsa -b 4096 -q -N '' -f ~/.ssh/id_rsa_dasomoli_nas
ssh-copy-id -i ~/.ssh/id_rsa_dasomoli_nas.pub dasomoli@nas.dasomoli.org

ssh 접속 시 no matching key exchange method found. 문제

SSH 접속 시 다음과 같은 에러가 발생할 때가 있다.

Unable to negotiate with blog.dasomoli.org: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

OpenSSH가 7.0이상이면, 요 키 교환 알고리즘이 기본으로 켜져 있지 않아서 나는 문제인데, 다음과 같은 방법으로 해결 가능하다.

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@host

이걸 명령 줄 때마다 하긴 귀찮으니까 ~/.ssh/config 파일 안에 다음 내용을 추가하면 된다.

Host blog.dasomoli.org
KexAlgorithms +diffie-hellman-group1-sha1

참고: Using OpenSSH with legacy SSH implementations