在签出开发服务器上的分支后,我尝试使用开发服务器上的rsync将文件下载到本地计算机。
在使用wsl2之前,我曾经能够完成以下操作:
远程服务器
rsync -ave "ssh -p 22001" --delete --exclude-from ~/rsync_exclude_list.txt ~/as/ alex@localhost:/home/alexmk92/code/project本地SSH配置
Host dev-tunnel
HostName dev.sever.co.uk
User as
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h:%p
RemoteForward 22001 localhost:22
Host dev
HostName dev.server.co.uk
User as
RequestTTY yes
RemoteCommand cd as; bash然后,我可以使用ssh dev和ssh -fvN dev-tunnel运行这些,如果在远程服务器上输入ssh -p 22001 alex@localhost,则得到:
debug1: remote forward success for: listen 22001, connect localhost:22
debug1: All remote forwarding requests processed
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 2 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 22001, originator 127.0.0.1 port 34472
debug1: connect_next: host localhost ([127.0.0.1]:22) in progress, fd=5
debug1: channel 1: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connection failed: Connection refused
connect_to localhost port 22: failed.
debug1: channel 1: free: 127.0.0.1, nchannels 2我猜这是因为WSL2不再在本地主机上运行,而是在Hypervisor中被隔离。这可能意味着windows在localhost:22 (没有运行SSH服务器的地方)接收到这个请求,然后挂断连接。
如何将请求转发到我的WSL2 SSH进程?
发布于 2021-04-18 12:37:11
可以使用以下WSH脚本向WSL2机器添加端口映射:
$port = 3000;
$addr = '0.0.0.0';
$remoteaddr = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteaddr -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ) {
$remoteaddr = $matches[0];
} else {
echo "Error: ip address of WSL 2 cannot be found";
exit;
}
Invoke-Expression "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr"
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteaddr"
echo "Success: Port mapping added!";当然,您需要更改为端口,也许IP地址(前两行)可能需要以管理员的身份运行脚本.
https://stackoverflow.com/questions/67006297
复制相似问题