멀티홉 및 프롬프트 인증을 위한 ProxyCommand

멀티홉 및 프롬프트 인증을 위한 ProxyCommand

다음 명령을 어떻게 다시 작성할 수 있습니까 ProxyCommand?

ssh -l username1 -t jumphost1 \
ssh -l username2 -t jumphost2 \
ssh -l username3 -t jumphost3 \
ssh -l username4    server

이건 작동하지 않아

ssh -o ProxyCommand="\
ssh -l username1 -t jumphost1  \
ssh -l username2 -t jumphost2  \
ssh -l username3 -t jumphost3" \
    -l username4    server

username1@jumphost1's password:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
ssh_exchange_identification: Connection closed by remote host

와 함께 작동한다는 것을 알고 있지만 nc3개 이상의 홉과 함께 사용하고 이 옵션도 와 함께 사용할 수 있는 방법을 찾고 있습니다 scp. 매뉴얼 페이지를 확인했지만 ssh_config적어도 나에게는 정보가 매우 드물었습니다.

편집하다

아래 제안된 대로 ProxyCommand다른 항목 내에 중첩된 기능을 사용해 보았지만 ProxyCommand항상 다음과 같은 결과가 나타납니다.

debug3: ssh_init_stdio_forwarding: 192.17.2.2:2222
debug1: channel_connect_stdio_fwd 192.17.2.2:2222
debug1: channel 0: new [stdio-forward]
debug2: fd 4 setting O_NONBLOCK
debug2: fd 5 setting O_NONBLOCK
debug1: getpeername failed: Bad file descriptor
debug3: send packet: type 90
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.

다행스럽게도 7.3 -JOR은 ProxyJump내 목적에 부합했지만 여전히 주요 설정 문제를 해결해야 했습니다.

ssh -q -J user1@jumphost1,user2@jumphost2,user3@jumphost3 user@server

답변1

간단한 ssh구성 파일 사용

nc최신 버전에서는 이 버전을 사용하지 않는 것이 좋습니다 . 대신 최신 버전의 OpenSSH에서 스위치를 ssh사용하세요 . -W또한 구성을 다른 호스트에 복사할 필요가 없습니다! 모든 구성은 호스트에서 수행되어야 하며 scp어떤 식으로든 방해가 되지 않습니다.

~/.ssh/config다음은 해당 예제에 대한 샘플 파일입니다.

Host jumphost1
    User username1
Host jumphost2
    User username2
    ProxyCommand ssh -W %h:%p jumphost1
Host jumphost3
    User username3
    ProxyCommand ssh -W %h:%p jumphost2
Host server
    User username4
    ProxyCommand ssh -W %h:%p jumphost3

마지막으로, ssh server또는 scp file server:path/또는 을 사용하여 연결하세요 rsync.


메모

SSH 구성 파일에서 텍스트 대신 그림을 사용하려는 사용자를 위한 신호 흐름 다이어그램은 다음과 같습니다.

localhost
        ||
        \/
username1@jumphost1
        ||
        \/
username2@jumphost2
        ||
        \/
username3@jumphost3
        ||
        \/
username4@server


pps for fun 다음은 한 줄로 된 내용이지만 이 접근 방식은 입력하기 어렵고 읽기도 어렵다는 점에 유의하세요.

ssh -oProxyCommand= \
  'ssh -W %h:%p -oProxyCommand= \
    \'ssh -W %h:%p -oProxyCommand= \
      \\\'ssh -W %h:%p username1@jumphost1\\\' \
    username2@jumphost2\' \
  username3@jumphost3' \
username4@server

기본적으로 내부부터 시작해야 합니다.

답변2

나는 이미 이것을 했다홉, 하지만 3번은 작동할 것입니다. 가장 쉬운 방법은 ~/.ssh/config각 호스트에 이 파일을 설정하는 것입니다. 따라서 Hostc`를 통해 열고 hosta액세스 하려면 다음과 같이 구성을 설정할 수 있습니다.hostdhostb

존재하다 hosta:~/.ssh/config:

Host hostd
    User username
    ProxyCommand ssh hostb nc %h %p 2> /dev/null

존재하다 hostb:~/.ssh/config:

Host hostd
    User username
    ProxyCommand ssh hostc nc %h %p 2> /dev/null

존재하다 hostc:~/.ssh/config:

Host hostd
    User username
    ProxyCommand ssh hostd nc %h %p 2> /dev/null

ssh hostd그런 다음 체인의 모든 호스트에서 액세스 할 수 있습니다 hostd.

netcat을 프록시로 사용해도 방해가 되지 않습니다 scp.

어떤 이유로든 로컬 파일을 사용하고 싶지 않은 경우 ~/.ssh/config다음을 수행할 수 있습니다 hosta.

ssh -oProxyCommand='ssh -oProxyCommand=\'ssh -o ProxyCommand=\\\'ssh username@hostd nc %h %p 2>/dev/null\\\' username@hostc nc %h %p 2> /dev/null' username@hostb nc %h %p 2> /dev/null' username@hostd

관련 정보