Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:services:ssh:autossh [2018/03/04 07:40] – ↷ Page moved from docs:guide-user:services:autossh to docs:guide-user:services:ssh:autossh bobafetthotmaildocs:guide-user:services:ssh:autossh [2022/03/25 10:50] – [Run as Service] trendy
Line 11: Line 11:
   * [[https://github.com/aa65535/openwrt-autossh]]   * [[https://github.com/aa65535/openwrt-autossh]]
  
-[[docs:guide-user:services:sshtunnel|sshtunnel]] is a simpler, functionally-identical package. (depends on OpenSSH so higher disk space requirements)+[[docs:guide-user:services:ssh:sshtunnel|sshtunnel]] is a simpler, functionally-identical package. (depends on OpenSSH so higher disk space requirements)
  
 ===== Use Case ===== ===== Use Case =====
Line 28: Line 28:
 ===== Configuration ===== ===== Configuration =====
 Autossh is configured using the [[docs:guide-user:base-system:uci| Unified Configuration Interface]] (''/etc/config/autossh'').  Autossh is configured using the [[docs:guide-user:base-system:uci| Unified Configuration Interface]] (''/etc/config/autossh''). 
 +
 +A typical confiugration is as follows:
 +<code>
 +config autossh
 +        option ssh      '-i /root/.ssh/dropbear -N -T -R remote_port:localhost:22 your_romote_host_user_name@your_remote_host'
 +        option gatetime '0'
 +        option monitorport      '20000'
 +        option poll     '100'
 +        option enabled  '1'
 +</code>
 +
 +You need to eplace ''/root/.ssh/dropbear'' with your key generated by dropbear.
 +
 +===== Run as Service =====
 +
 +Autossh is often used as reverse proxy. It's probably because your ISP does not give you a public address or your router firewall policies. To make autossh run even when router restarts, your need to set up a service.
 +
 +In ''/etc/init.d/autossh'', most content of the files has been generated when you first install autossh. But you need add a line ''procd_set_param env HOME="/root"'' in ''start_instance()'' or the the service will **NOT** work when the router reboots. This is a known bug not fixed yet. https://github.com/openwrt/packages/issues/5559
 +
 +
 +
 +        start_instance() {
 +                local section="$1"
 +        
 +                config_get ssh "$section" 'ssh'
 +                config_get gatetime "$section" 'gatetime'
 +                config_get monitorport "$section" 'monitorport'
 +                config_get poll "$section" 'poll'
 +                config_get_bool enabled "$section" 'enabled' '1'
 +                
 +                [ "$enabled" = 1 ] || exit 0
 +                
 +                procd_open_instance
 +                procd_set_param command /usr/sbin/autossh -M ${monitorport:-20000} ${ssh}
 +                procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
 +                procd_set_param env AUTOSSH_GATETIME="${gatetime:-30}" 
 +                procd_set_param env AUTOSSH_POLL="${poll:-600}"
 +                procd_set_param env HOME="/root"
 +                procd_close_instance
 +
 +
 +Now you can enable the service by ''/etc/init.d/autossh enable'' and enjoy it.
  
 ===== Fixes ===== ===== Fixes =====
 To get ssh working you need to replace ''localhost'' in ''2222:localhost:22'' of the ''ssh'' variable to the local ip.  To get ssh working you need to replace ''localhost'' in ''2222:localhost:22'' of the ''ssh'' variable to the local ip. 
  
  • Last modified: 2023/11/30 22:27
  • by stokito