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
docs:user-guide:services:autossh [2018/02/25 15:37] – ↷ Links adapted because of a move operation docs:guide-user:services:ssh:autossh [2023/11/30 22:27] (current) – [Autossh] stokito
Line 11: Line 11:
   * [[https://github.com/aa65535/openwrt-autossh]]   * [[https://github.com/aa65535/openwrt-autossh]]
  
-[[docs:user-guide: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.
  
 ===== Use Case ===== ===== Use Case =====
Line 27: Line 27:
  
 ===== Configuration ===== ===== Configuration =====
-Autossh is configured using the [[docs:user-guide: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 configuration is as follows: 
 +<code> 
 +config autossh 
 +        option ssh      '-i /root/.ssh/dropbear -N -T -R 2222:192.168.1.1:22 remote_host_user_name@remote_host' 
 +        option gatetime '0' 
 +        option monitorport      '20000' 
 +        option poll     '100' 
 +        option enabled  '1' 
 +</code> 
 + 
 +You need to replace ''/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 
 + 
 + 
 +For the first time you connect, you need to make sure that the server is in the trusted-host list, otherwise autossh will restart in a loop. 
 +  user.info autossh[17709]: starting ssh (count 10) 
 +  user.info autossh[17709]: ssh child pid is 17742 
 +  user.info autossh[17709]: ssh exited with error status 1; restarting ssh 
 +Just run an ''ssh -p port user@host'' and accept. 
 +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