当前位置: 代码网 > it编程>编程语言>Java > windows本地主机和ubuntu服务器创建ssh隧道

windows本地主机和ubuntu服务器创建ssh隧道

2024年08月02日 Java 我要评论
C:Usersdyf.ssh目录下id_rsa.pub里的值复制到ubuntu服务器的/root/.ssh/authorized_keys文件里。复制到windows的C:Usersdyf.ssh目录下。windows上的127.0.0.1:8083可以接收到666。在C:Usersdyf.ssh目录下执行cmd命令。windows上的端口8083。2、windows本地主机。4、windows本地主机。1、ubuntu服务器。3、ubuntu服务器。5、ubuntu服务器。

windows上的端口8083
ubuntu上的端口9781
666.com是ubuntu服务器地址

1、ubuntu服务器

创建秘钥
ssh-keygen

进入秘钥目录
cd /root/.ssh/

下载私钥
sz id_rsa

复制到windows的c:\users\dyf\.ssh目录下

vim /etc/ssh/sshd_config

将#gatewayports no
改为
gatewayports yes

重启服务
systemctl restart sshd.service 


2、windows本地主机

创建秘钥
ssh-keygen -t rsa -b 4096

复制公钥
c:\users\dyf\.ssh目录下id_rsa.pub里的值复制到ubuntu服务器的/root/.ssh/authorized_keys文件里


3、ubuntu服务器

增加防火墙
sudo iptables -a input -p tcp --dport 9781 -j accept


4、windows本地主机

创建隧道
在c:\users\dyf\.ssh目录下执行cmd命令

ssh -i .\id_rsa -fcnr 9781:127.0.0.1:8083 -o serveraliveinterval=60 -o serveralivecountmax=120 -p 22 ubuntu@666.com

输入ubuntu服务器密码

5、ubuntu服务器

查看端口
netstat -antup | grep 9781

发送消息
echo '666' | nc 666.com 9781

接收消息
windows上的127.0.0.1:8083可以接收到666

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com