SSH 연결 설정이 너무 느림

SSH 연결 설정이 너무 느림

500MB RAM이 있는 로컬 Centos 6.3 VM에 연결하는 동안 문제가 발생했습니다.

아래는 연결 출력입니다 ssh -vvv localhost.

OpenSSH_6.3, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /usr/local/etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
^^^^^^^^^^ Loading this statement takes more than a minute

debug1: Connection established.
...

debug1: Next authentication method: password 
root@localhost's password:
^^^^^^^^^^ This step takes a minute too

debug3: packet_send2: adding 64 (len 50 padlen 14 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to localhost ([127.0.0.1]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Last login: Wed Oct  9 13:27:02 2013 from 10.0.0.2

이 지연을 제거하는 방법에 대해 제안해 주세요.

답변1

내 생각엔 문제는 DNS 요청 시간 초과인 것 같습니다. 호스트 이름 대신 IP 주소로 연결하고 UseDNS연결하려는 서버의 옵션을 꺼보세요. 그 이외의:

  1. VM 호스트에서 연결한다고 가정하면 ssh localhost게스트 VM이 아닌 호스트에 연결될 것으로 예상됩니다. 물론 흥미로운 네트워크 설정이 없다면 말이죠.

  2. 첫 번째 지연의 경우 이를 실행 strace하고 클라이언트가 걸려 있는 시스템 호출을 확인할 수 있습니다 ssh.

  3. 두 번째 지연의 경우 topVM에서 실행하여 연결하는 동안 무슨 일이 일어나고 있는지 확인하세요. 동시에 대체 포트에서 디버그 모드로 SSH 데몬을 실행하고 해당 인스턴스에 연결하는 것이 좋습니다. 대기 중인 위치를 확인할 수 있습니다. 루트로 실행하면 됩니다.

    sshd -ddd -p 2222 -o UsePrivilegeSeparation=no
    

    이렇게 하면 포트 2222에서 SSH 데몬이 시작되고 많은 정보( -ddd)가 기록되며 로그인 중에 권한 분리를 사용하지 않습니다. (권한 분리를 비활성화하면 하나의 프로세스만 사용되므로 strace에서 무슨 일이 일어나고 있는지 더 쉽게 확인할 수 있습니다.) . -o UseDNS=no위에서 언급한 옵션을 비활성화하도록 추가할 수도 있습니다 .

답변2

VM인 경우 엔트로피가 부족하기 때문일 수 있습니다.연결 시도 전/중에 사용 가능한 엔트로피를 모니터링하려면 다음 줄을 사용하세요.

while true; do sleep 5; cat /proc/sys/kernel/random/entropy_avail; done

연결 시도 중에 이미 매우 낮거나 크게 감소했다면 원인일 가능성이 매우 높습니다.

편집하다:이렇게 하면 새 프로세스를 시작하면 엔트로피가 소비되므로 사용 가능한 엔트로피 자체에 영향을 줍니다. 또한보십시오https://blog.flameeyes.eu/2011/03/entropy-broken

더 많은 엔트로피를 수집하는 데몬( rng-tools또는 clrngd)을 설치하거나 VM에 가상화 솔루션에 따라 적절한 엔트로피 장치가 할당되어 있는지 확인하여 사용 가능한 엔트로피를 늘릴 수 있습니다.

관련 정보