Start up as CentOS7 systemd service


  1. create service file
        # vi /usr/lib/systemd/system/myproxy.service
        [Unit]
        Description=SSH tunnel to proxy server
        Wants=network-online.target
        After=network-online.target
    
        [Service]
        Type=forking
        ExecStart=/usr/bin/ssh -NfD 1080 -i /root/.ssh/id_rsa johnson@jserver
    
        [Install]
        WantedBy=multi-user.target
        
  2. config ssh client keepalive
        # vi /etc/ssh/ssh_config
        Host *
            # the keepalive msg to send before disconnected
            ServerAliveCountMax 2
            # in seconds
            ServerAliveInterval 60
        
  3. enable service
        systemctl enable myproxy.service
        
  4. start service
        systemctl start myproxy.service