在OpenWRT上怎么使用 sshtunnel (autossh)

卸载dropbear并安装openssh

openwrt 自带的 ssh 是 dropbear,是 openssh 的小型版。

个人感觉非常难用,因此需要先卸载 dropbear 并安装 openssh,具体步骤如下:

  1. 更改 dropbear 的端口为 2222,然后重启 dropbear。
uci set dropbear.@dropbear[0].Port=2222
uci commit dropbear
/etc/init.d/dropbear restart
  1. 退出终端,再使用 2222 端口重新登录 openwrt。
ssh -p 2222 root@192.168.5.1
  1. 安装 openssh 的服务端和客户端。
opkg update
opkg install openssh-server
opkg install openssh-client
opkg install openssh-sftp-server # 对 sshfs 支持, 可不装
  1. 修改 openssh 的配置。
# 修改配置文件
vim /etc/ssh/sshd_config
# 将以下内容进行修改
PermitRootLogin yes # 开启 root 用户直接登录
PasswordAuthentication yes # 开启密码登录
GatewayPorts yes # 开启端口访问
  1. 自启或重启 openssh。
/etc/init.d/sshd enable
/etc/init.d/sshd start
/etc/init.d/sshd restart
  1. 退出终端,再使用 22 端口重新登录 openwrt。
ssh root@192.168.5.1
  1. 卸载 dropbear。
/etc/init.d/dropbear disable
/etc/init.d/dropbear stop
opkg remove dropbear
图片[1]-在OpenWRT上怎么使用 sshtunnel (autossh)-不念博客

安装和配置sshtunnel

  1. 首先安装 sshtunnel。
opkg update
opkg install sshtunnel

sshtunnel 中包括 tunnelR, tunnelL, tunnelD, tunnelW,其中前三项和 autossh 中的 -R, -L, -D 功能相同,tunnelW 我没太搞懂怎么用。

  1. 编辑 sshtunnel 的配置。
vim /etc/config/sshtunnel

我的配置如下。注意公私钥需要事先放在对应目录。

config server myserver
        option user                     wang
        option hostname                 <远程服务器 IP>
        option port                     22
        option retrydelay               1
        option CheckHostIP              yes
        option Compression              no
        option CompressionLevel         6
        option IdentityFile             <私钥位置>
        option LogLevel                 INFO
#       option PKCS11Provider           /lib/pteidpkcs11.so
        option ServerAliveCountMax      3
        option ServerAliveInterval      60
        option StrictHostKeyChecking    accept-new
        option TCPKeepAlive             yes
        option VerifyHostKeyDNS         yes

config tunnelL jellyfin
       option server           myserver
       option localaddress     *
       option localport        8096
       option remoteaddress    127.0.0.1
       option remoteport       8096

config tunnelL filebrowser
       option server           myserver
       option localaddress     *
       option localport        8080
       option remoteaddress    127.0.0.1
       option remoteport       8080

config tunnelL jupyterlab
       option server           myserver
       option localaddress     *
       option localport        8888
       option remoteaddress    127.0.0.1
       option remoteport       8081
  1. 运行 sshtunnel。
/etc/init.d/sshtunnel enable
/etc/init.d/sshtunnel start
/etc/init.d/sshtunnel status
© 版权声明
THE END
喜欢就支持一下吧
点赞84赞赏 分享
评论 抢沙发
头像
欢迎光临不念博客,留下您的想法和建议,祝您有愉快的一天~
提交
头像

昵称

取消
昵称

    暂无评论内容