Skip to content

Instantly share code, notes, and snippets.

@pzxbc
Last active March 4, 2019 05:43
Show Gist options
  • Save pzxbc/89d49f77e6ccf5c147990ed3d45aabd3 to your computer and use it in GitHub Desktop.
Save pzxbc/89d49f77e6ccf5c147990ed3d45aabd3 to your computer and use it in GitHub Desktop.
autossh systemd service unit file
[Unit]
Description=autossh connect
After=network-online.target ssh.service
[Service]
ExecStart=/usr/bin/autossh -M 40000 -N -q pi3
ExecStop=killall -s KILL autossh
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
@pzxbc
Copy link
Author

pzxbc commented Mar 4, 2019

autossh 自动连接的systemd服务配置文件

需要在.ssh目录下配置对应的ssh连接选项

配置文件存放于/lib/systemd/system目录下

编辑完成后,使用下面命令生效

sudo systemctl daemon-reload
sudo systemctl enable autossh_connect.service
sudo systemctl start autossh_connect.service

@pzxbc
Copy link
Author

pzxbc commented Mar 4, 2019

ssh config for pi3

Host pi3
	HostName xxx.com
	Port 22
	User pi
	ServerAliveInterval 60
	GatewayPorts yes
	ControlMaster auto
	ControlPath /tmp/ssh_mux_%h_%p_%r
	RemoteForward *:8080 localhost:22
	StrictHostKeyChecking no
	IdentityFile ~/.ssh/id_rsa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment