ssh 隧道—绑定:地址已在使用中

ssh 隧道—绑定:地址已在使用中

Ubuntu 20.04.1 LTS我在我的 VPS和本地上运行Ubuntu 18.04.3 LTS,我想创建一个 ssh 隧道来连接到我的数据库以SELECT在我的应用程序中运行报告laravel 6

我的生产数据库在我的服务器上具有以下凭据:

DB_HOST_PROD=127.0.0.1
DB_PORT_PROD=3306
DB_DATABASE_PROD=test_db
DB_USERNAME_PROD=root
DB_PASSWORD_PROD=prod_pwd

运行我的时ssh-command我得到:

admin@admin-VirtualBox:~$ /usr/bin/ssh -o StrictHostKeyChecking=no -v -N -i /home/admin/.ssh/id_rsa -L 13307:127.0.0.1:3306 -p 22 [email protected]
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to xx.xx.xxx.xx [xx.xx.xxx.xx] port 22.
debug1: Connection established.
debug1: identity file /home/admin/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/admin/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xx.xx.xxx.xx:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:aaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaa
debug1: Host 'xx.xx.xxx.xx' is known and matches the ECDSA host key.
debug1: Found key in /home/admin/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /home/admin/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to xx.xx.xxx.xx ([xx.xx.xxx.xx]:22).
debug1: Local connections to LOCALHOST:13307 forwarded to remote address 127.0.0.1:3306
debug1: Local forwarding listening on ::1 port 13307.
bind: Address already in use
debug1: Local forwarding listening on 127.0.0.1 port 13307.
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 13307
Could not request local forwarding.
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding

我在本地运行我的开发数据库:

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test_db
DB_USERNAME=root
DB_PASSWORD=local_pwd

我为什么会收到该消息bind: Address already in use

有什么建议我做错了吗?

答案1

该消息不言自明。某些程序已在使用端口 13307。尝试netstat -antp以 root 身份运行,查找端口 13307,您应该会看到相关程序的 PID。您可能已经有一个过时的 SSH 连接。此外,您可能需要 -R 选项来进行反向 SSH。

可能有用的帖子:知道远程端口转发是否成功?

相关内容