You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=90
  3. STOP=10
  4. USE_PROCD=1
  5. PROG=/usr/bin/tmate-ssh-server
  6. generate_keys() {
  7. mkdir -p "$1"
  8. echo "Generating fresh keys"
  9. ssh-keygen -t "rsa" -f "$1/ssh_host_rsa_key" -N '' > /dev/null
  10. ssh-keygen -t "ed25519" -f "$1/ssh_host_ed25519_key" -N '' > /dev/null
  11. }
  12. start_service() {
  13. local ip hostname keys_dir listen_port ssh_port_advertized
  14. config_load "tmate-http-server"
  15. procd_open_instance
  16. procd_set_param command $PROG
  17. config_get ip main ip
  18. if [ ! -z "$ip" ]; then
  19. procd_append_param command -b "$ip"
  20. fi
  21. config_get hostname main hostname "$HOSTNAME"
  22. procd_append_param command -h "$hostname"
  23. config_get keys_dir main keys_dir "/etc/tmate-ssh-server/keys/"
  24. if [ ! -f "$keys_dir/ssh_host_rsa_key" ] && \
  25. [ ! -f "ssh_host_ed25519_key" ]; then
  26. generate_keys "$keys_dir"
  27. fi
  28. procd_append_param command -k "$keys_dir"
  29. config_get listen_port main listen_port "2222"
  30. procd_append_param command -p "$listen_port"
  31. config_get ssh_port_advertized main ssh_port_advertized "$listen_port"
  32. procd_append_param command -q "$ssh_port_advertized"
  33. echo "You may use the following settings this in your .tmate.conf:"
  34. echo ""
  35. echo "set -g tmate-server-host $hostname"
  36. echo "set -g tmate-server-port $ssh_port_advertized"
  37. printf "set -g tmate-server-rsa-fingerprint "
  38. ssh-keygen -l -E SHA256 -f "$keys_dir/ssh_host_rsa_key.pub" | \
  39. cut -d ' ' -f 2
  40. printf "set -g tmate-server-ed25519-fingerprint "
  41. ssh-keygen -l -E SHA256 -f "$keys_dir/ssh_host_ed25519_key.pub" | \
  42. cut -d ' ' -f 2
  43. procd_set_param respawn
  44. procd_set_param stdout 1
  45. procd_set_param stderr 1
  46. procd_close_instance
  47. }
  48. service_triggers() {
  49. procd_add_reload_trigger "tmate-ssh-server"
  50. }