Take the local 1470
port (my sqli-labs) and 9023
the port of vps as an example.
The basic SSH connection command is:
ssh username@hostname
Two hosts are involved here. One is the host that executes commands and runs the SSH client. We call it the local host A [Host A]. The second is the host that receives the connection request and runs the SSH server. We call it the remote host B [Host B]. 】. After verification through password or key, etc., the SSH connection is established, and host A can use the command line to remotely control host B.
In the above command, username is the logged-in user name on host B, and hostname is the device name, domain name or IP of host B that can be located on the network (LAN or Internet).
The actual operation steps are as follows: (Take the local 1470
port (my sqli-labs) and the vps 9023
port as an example.)
Host connection to vps: (uploaded from the host)
ssh -R 9023:localhost:1470 root@vps-ip
-R:指定远程端口转发
9023:自定义端口
localhost:1470:主机ip:主机相关服务的端口(sqli-labs的端口)
root:vps用户名
vps-ip:vps的ip地址,比如46.46.132.184
Enter the vps password
Make sure the external network can also access: (executed on vps)
GatewayPorts yes ensures that the external network can also access the listening port 9023 of this vps, instead of being only accessible by the localhost of the vps.
sudo echo 'GatewayPorts yes' >> /etc/ssh/sshd_config
sudo service ssh restart #重启ssh
Access http://vps-ip:9023/
, you can access sqlilabs on my host.
Reference article:
Detailed practical explanation of SSH remote port forwarding - Xi-iX - Blog Park (cnblogs.com)
Detailed explanation of ssh configuration in Linux_linux ssh_Mu Jinxuan's blog-CSDN blog
Thoroughly understand the SSH port forwarding command - Zhihu (zhihu.com)
[Nine common methods of Linux port forwarding_Dai Guojin’s blog-CSDN blog](https://blog.csdn.net/JineD/article/details/118254041#:~:text=SSH port forwarding 1 (1) Local Port forwarding ssh -fgN -L,%2Fetc%2Fsysctl.conf %23Add a line net.ipv4.ip_forward%3D1 %2F%2F to enable the data forwarding function sysctl -p (2) Forward the local port to the local port)