我在一台遥远的机器上安装了GitLab。现在我想把8080端口从这台遥远的机器转发到我的本地端口8080。
在遥远的机器上:
sudo docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 8080:80 --publish 2222:22 --name gitlab --restart always --volume $GITLAB_HOME/config:/etc/gitlab --volume $GITLAB_HOME/logs:/var/log/gitlab --volume $GITLAB_HOME/data:/var/opt/gitlab gitlab/gitlab-ce:latest在我的本地机器上:
ssh -N -o "ExitOnForwardFailure yes" -R 8080:localhost:8080 someuser@the-distant-server -vvv我得到以下错误:
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug3: receive packet: type 4
debug1: Remote: /home/someuser/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug3: receive packet: type 82
debug1: remote forward failure for: listen 8080, connect localhost:8080
Error: remote port forwarding failed for listen port 8080实际上,在/var/log/auth.log中,我得到了以下错误:
Jul 9 16:51:42 distant-server sshd[2723782]: Accepted publickey for someuser from 192.168.200.182 port 44850 ssh2: RSA SHA256:
Jul 9 16:51:42 distant-server sshd[2723782]: pam_unix(sshd:session): session opened for user someuser by (uid=0)
Jul 9 16:51:42 distant-server systemd-logind[1083]: New session 116923 of user someuser.
Jul 9 16:51:42 distant-server systemd[2723795]: pam_unix(systemd-user:session): session opened for user someuser by (uid=0)
Jul 9 16:51:43 distant-server sshd[2723812]: error: bind [127.0.0.1]:8080: Address already in use
Jul 9 16:51:43 distant-server sshd[2723812]: error: channel_setup_fwd_listener_tcpip: cannot listen to port: 8080
Jul 9 16:51:43 distant-server sshd[2723782]: pam_unix(sshd:session): session closed for user someuser
Jul 9 16:51:43 distant-server systemd-logind[1083]: Session 116923 logged out. Waiting for processes to exit.
Jul 9 16:51:43 distant-server systemd-logind[1083]: Removed session 116923.它告诉我bind [127.0.0.1]:8080: Address already in use。
ssh命令以使隧道正常工作并访问GitLab实例?发布于 2021-07-09 15:53:57
简单回答:使用ssh开关-L而不是-R。
说明:在遥远的机器上,你打开一个码头集装箱,它发布8080港口。这意味着,对接主机将打开一个LISTEN套接字并等待传入的连接。
端口转发有两种类型:-L和-R:
-L在本地机器上打开一个侦听套接字,并通过ssh隧道转发这个传入连接,并在远程主机上打开一个连接到指定的地址(本例中为localhost:8080,这正是您想要的)。-R的工作方式正好相反:它等待远程计算机上的传入连接,并将其转发给本地主机。当然,这会失败,因为您已经在这个地址上安装了一个侦听套接字(码头容器!)你总是要考虑是谁发起了连接。Gitlab实例可能可以通过浏览器访问,这意味着您的本地浏览器试图打开连接,因此您必须在本地使用侦听套接字。
https://serverfault.com/questions/1069132
复制相似问题