在Linux上建立ssh隧道

本文介绍SSH隧道配置的方法,包括如何使用ssh命令建立本地端口转发,以及如何通过一系列选项优化SSH会话,使其更适合用于隧道转发。文中详细解释了各参数的作用,如:-L指定本地端口与远程主机端口之间的隧道;-q、-T、-f等选项则有助于提高SSH隧道的性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

ssh -L 7070:localhost:* remotehost

 

上 面的命令行中,-L指定本地端口与远程主机端口之间的隧道, 7070是本地端口,可以任意设置,只要不和其他已经使用的网络服务冲突就可以。localhost是本地主机,也就是你的电脑,不用更改,*号可以自动 寻找远程主机可用的端口。remotehost就是所要登录的远程SSH主机名称。

 

ssh -qTfnN -D 7070 remoteho st

All the added options are for a ssh session that’s used for tunneling.

-q :- be very quite, we are acting only as a tunnel.
-T :- Do not allocate a pseudo tty, we are only acting a tunnel.
-f :- move the ssh process to background, as we don’t want to interact with this ssh session directly.
-N :- Do not execute remote command.
-n :- redirect standard input to /dev/null.

In addition on a slow line you can gain performance by enabling compression with the -C option.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值