ubuntu使用frp内网穿透SSH服务

准备工作

服务器端

  • 将下载好的frp中的内容解压在root下的frp目录中,确保文件路径为 /root/frp/frps.toml
  • frps.toml文件内容更改为:bindPort = 10086
  • 创建frps服务,在 /etc/systemd/system/ 目录下创建 frps.service 文件,内容修改为:
[Unit]
Description = frp server
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
ExecStart = /root/frp/frps -c /root/frp/frps.toml
[Install]
WantedBy = multi-user.target
  • 执行:sudo systemctl start frps.service启动服务端
  • 执行:sudo systemctl enable frps.service设置服务开机自启
  • 执行:sudo systemctl status frps.service查看服务状态,确保输出结果中状态应为 active,类似于:
● frps.service - frp server
     Loaded: loaded (/etc/systemd/system/frps.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-01-08 12:45:43 CST; 1h 28min ago
   Main PID: 67887 (frps)
      Tasks: 6 (limit: 4643)
     Memory: 11.4M
        CPU: 702ms
     CGroup: /system.slice/frps.service
             └─67887 /root/frp/frps -c /root/frp/frps.toml
  • 服务器端的准备工作就完成了

客户端

  • 首先需要确保客户端能够成功访问到VPS服务器
  • 执行:sudo apt install openssh-server -y安装ssh服务
  • 执行:sudo systemctl start ssh启动服务
  • 执行:sudo systemctl enable ssh设置服务开机自启
  • 执行:sudo systemctl status ssh,确保输出状态为 active
  • 将下载好的frp中的内容解压在root下的frp目录中,确保文件路径为 /root/frp/frpc.toml
  • frpc.toml文件内容更改为如下内容,其中x.x.x.x更改为你的VPS服务器端公网IP地址:
serverAddr = "x.x.x.x"
serverPort = 10086

[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
  • 创建frpc服务,在 /etc/systemd/system/ 目录下创建 frpc.service 文件,内容修改为:
[Unit]
Description = frp client
After = network.target
Wants = network.target
[Service]
Restart = on-failure
RestartSec = 5
ExecStart = /root/frp/frpc -c /root/frp/frpc.toml
[Install]
WantedBy = multi-user.target
  • 然后执行:sudo systemctl start frpc.service启动服务
  • 然后执行:sudo systemctl enable frpc.service设置服务开机自启
  • 然后执行:sudo systemctl status frpc.service查看服务状态,确保输出结果中状态应为 active,类似于:
● frpc.service - frp client
     Loaded: loaded (/etc/systemd/system/frpc.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-01-08 12:32:27 CST; 1h 13min ago
   Main PID: 69436 (frpc)
      Tasks: 6 (limit: 4643)
     Memory: 5.7M
        CPU: 609ms
     CGroup: /system.slice/frpc.service
             └─69436 /root/frp/frpc -c /root/frp/frpc.toml
  • 客户端的准备工作就完成了

使用方法

在任意能访问到VPS服务器的机器上,使用如下命令登陆,其中x.x.x.x是你的VPS服务器的公网IP地址

ssh -o Port=6000 test@x.x.x.x
或
ssh -p 6000 test@x.x.x.x

参考

frp官方文档https://gofrp.org/zh-cn/docs/

posted @ 2025-01-08 14:42  漫天残星  阅读(90)  评论(0编辑  收藏  举报