服务安装
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@远程端口
网友评论