포트 전달 및 로컬 컴퓨터로 다시 복사

포트 전달 및 로컬 컴퓨터로 다시 복사

나는 일반적으로 SSH를 통해 네트워크에 로그인한 다음 다시 SSH를 통해 최종 대상 컴퓨터에 로그인합니다. 예를 들어 홈 서버와 우리 가족의 컴퓨터 중 하나에 연결됩니다. 그것은 다음과 같습니다:

user0@inital:> ssh -P port_number user1@server
user1@server:> ssh -P port_number user2@final
user2@final:>

일단 user2@final(scp)를 다시 user0@inital.

예를 들어 로컬 포트 ​​전달을 수행하고 로컬 컴퓨터에서 서버를 통해 원격 컴퓨터로 복사할 수 있습니다. ~에user0@initial

 user0@initial:> ssh -L4321:final:22 -p 443 user1@server

그러면 로컬 포트 4321​​양식이 user0@initialuser1@server포트로 22전달 됩니다 user2@final. 그런 다음 user0@initial실행하여

  scp -P 4321 some_file  [email protected]:~/

user2@final이상 으로 복사할 수 있습니다 user1@server.

문제는 상황을 되돌리고 에서 으로 다시 복사하는 방법 user2@final입니다 user0@initial.

도움을 주셔서 감사합니다.

답변1

final의 명령 프롬프트에서 scp 명령을 실행한다고 가정합니다.

# have the local client tell the remote server's sshd to listen on
# port 8765 (randomly chosen) and forward any connection it receives
# to the client which will connect to port 22 locally.
user0@initial:> ssh -R127.0.0.1:8765:127.0.0.1:22 -p 443 user1@intermediate

# On this machine have the client tell this remote server's (final's)
# to listen on port 9876 (randomly chosen) and forward any connection
# that it receives back to this client which will connect it to poirt
# 8765 locally.
user1@intermediate:> ssh -R127.0.0.1:9876:127.0.0.1:8765 user2@final

# Now that you are on the final server (final) you run scp, telling
# it to connect to localhost on port 9876.
# 
# So scp will connec to local (final's) port 9876, which is listened
# to by the local sshd based on our second command above.  That sshd
# will forward the connection to the ssh client that connected to it
# (on intermediate).
# 
# The ssh client on intermediate will connect to localhost:8765 as
# instructed which is a conenction to the sshd on intermediate that
# is listening on that port because it was instructed to do so by the
# ssh client on initial when it connected.
# 
# The sshd on intermediate will forward the conenction back to the
# client on initial which will, as instructed, connect to localhost:22
# on initial.
# 
# All this monkey motion means that now scp on final is "directly"
# connected to port 22 (sshd) on initial and can initiate a login
# and file transfer. to the ssh client that connected to it (on
# intermediate).
user2@final:> scp -P 9876 file_from_final 127.0.0.1:back_at_the_house

포트를 모두 127.0.0.1에 만들었기 때문에 인터넷상의 다른 사람(그러나 "서버" 또는 "최종"의 다른 사람의 악용은 아님)으로부터 포트를 보호합니다.

답변2

예. ssh_config 키워드를 살펴보고 싶을 것입니다프록시 명령

서버에 연결하는 데 사용할 명령을 지정합니다. 명령 문자열은 줄 끝까지 확장되며 느린 쉘 프로세스를 피하기 위해 사용자의 쉘 ​​'exec' 지시문을 사용하여 실행됩니다.

명령 문자열에서 '%h'는 연결할 호스트 이름으로 대체되고, '%p'는 포트로, '%r'은 원격 사용자 이름으로 대체됩니다. 명령은 기본적으로 무엇이든 될 수 있으며 표준 입력에서 읽고 표준 출력에 써야 합니다. 결국 일부 시스템에서 실행 중인 sshd(8) 서버에 연결하거나 어딘가에서 sshd -i를 실행해야 합니다. 호스트 키 관리는 연결되는 호스트의 HostName을 사용하여 수행됩니다(기본값은 사용자가 입력한 이름). 명령을 "none"으로 설정하면 이 옵션이 완전히 비활성화됩니다. 프록시 명령을 사용한 연결에는 CheckHostIP를 사용할 수 없습니다.

이 지시문은 nc(1) 및 해당 프록시 지원과 함께 유용합니다. 예를 들어 다음 지시문은 192.0.2.0에서 HTTP 프록시를 통해 연결됩니다.

ProxyCommand /usr/bin/nc -X connect -x 192.0.2.0:8080 %h %p

관련 정보