SlothのBlog

  • 首页
  • 分类
    • 教程
    • 释义
    • 分享
  • 服务器
  1. 首页
  2. 教程
  3. 正文

内网穿透 - AutoSSH

2024年1月20日 0条评论

前言

AutoSSH是基于原生ssh而实现端口转发, 本教程只演示内网穿透这一用途

为了穿透掉线重连实现无密码连接SSH, 远程机(公网机)请务必使用SSH-KEY的验证方式

一键脚本

以下为本人自己编写的一键脚本, 若不放心, 请移步后面的手动安装教程


bash <(curl -fsSL https://raw.githubusercontent.com/Slotheve/Shells/main/autossh.sh)

手动安装

远程机(公网机)设置SSH


echo 'GatewayPorts yes' >> /etc/ssh/sshd_config && \
echo 'TCPKeepAlive yes' >> /etc/ssh/sshd_config && \
echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config && \
echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config && \
systemctl restart sshd

本地机(内网机)安装 & 设置

1. 安装autossh


# apt
apt install -y autossh lsof

#yum

yum install -y autossh lsof

2. 创建autossh服务


touch /etc/systemd/system/autossh.service # 创建空服务文件

3. 填入以下代码


[Unit]
Description=AutoSSH
After=network-online.target

[Service]
User=root
ExecStart=/usr/bin/autossh -M 内网机未被占用随机端口 -NR 公网机未被占用随机端口(之后连接内网机所用):127.0.0.1:内网机内网ssh端口 root@公网IP -p 公网机公网ssh端口 -o "StrictHostKeyChecking no"
Restart=always

[Install]
WantedBy=multi-user.target

4. 设置开机自启并启动服务


systemctl daemon-reload
systemctl enable autossh.service
systemctl start autossh.service

提示: 一般启动失败大概率是端口被占用了, 或者是ssh-key文件权限问题

标签: autossh frp 内网穿透
最后更新:2024年1月20日

slotheve

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

文章目录
  • 前言
  • 一键脚本
  • 手动安装
    • 远程机(公网机)设置SSH
    • 本地机(内网机)安装 & 设置
标签聚合
nginx面板 frp nginxwebui 内网穿透 wordpress mynodequery docker cmd docker nginx

COPYRIGHT © 2024 SlothのBlog. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang