ssh代理,内网服务器映射到公网服务器连接

服务安装

yum install -y autossh

安装autossh问题

如果yum install -y autossh没有找到package的话需要更换源

# 备份原来源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 重新下载源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-{system-version}.repo

服务配置

/lib/systemd/system/autossh@.service(yum安装后就已存在,将User修改为ROOT即可)

[Unit]
Description=autossh: %I
Documentation=file:///usr/share/doc/autossh/README.service man:autossh(1)
After=network.target

[Service]
User=root
Environment="AUTOSSH_GATETIME=0"
EnvironmentFile=/etc/autossh/%i.conf
ExecStart=/usr/bin/autossh $OPTIONS

[Install]
WantedBy=multi-user.target
PS: User=root

创建SSH连接

ssh-keygen # 全部回车
ssh-copy-id -i ~/.ssh/id_rsa.pub 用户@IP # 上传认证的RSA证书

配置文件

echo "OPTIONS=-M 监视端口 -NR 远程端口:127.0.0.1:ssh端口 -i /root/.ssh/id_rsa root@IP" > /etc/autossh/远程端口.conf

使用命令

systemctl enable autossh@远程端口
systemctl start autossh@远程端口
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容