惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
雷峰网
雷峰网
博客园_首页
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
小众软件
小众软件
D
Docker
P
Proofpoint News Feed
B
Blog
Vercel News
Vercel News
B
Blog RSS Feed
U
Unit 42
月光博客
月光博客
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
I
InfoQ
Recent Announcements
Recent Announcements

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 A RC script for freebsd frpc 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自建DERP服务器提升Tailscale连接速度(使用Nginx转发) 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例)
使用autossh实现内网穿透
Jiajun Huang · 2019-01-12 · via Jiajun的技术笔记

如果想要随时随地访问自己的笔记本该怎么做?不用搜了,当然是用强大的ssh。

$ ssh -NR 1234:localhost:22 -i /home/autossh/.ssh/id_rsa [email protected]

-R 的作用就是把远端的某个端口的流量转发到本地,也就是说,监听在远端主机的 1234,流量会被转发到 localhost:22 上。

直接使用上述命令即可,但是有一个问题,ssh可能会掉线,因此需要autossh。我们写成systemd的unit文件,这样可以开机自启。

[Unit]
Description=Keeps a tunnel to 'example.com' open
After=network.target

[Service]
User=autossh
ExecStart=/usr/bin/autossh -M 5678 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -NR 1234:localhost:22 -i /home/autossh/.ssh/id_rsa [email protected]
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

放到 /etc/systemd/system/autossh.service 这个文件里,然后新建一个autossh用户并且切换到该用户下,生成ssh密钥,把公钥加到对应的公网机器上。

$ sudo useradd -m autossh
$ sudo su autossh
$ ssh-keygen
$ cat ~/.ssh/id_rsa.pub