nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

ssh-tunnel.nix (669B)


      1 { pkgs, username, domain, sshport, privatekey, ... }:
      2 
      3 {
      4   systemd.services.reverse-ssh-tunnel = {
      5     description = "Persistent Reverse SSH Tunnel";
      6     after = [ "network-online.target" ];
      7     wants = [ "network-online.target" ];
      8     wantedBy = [ "multi-user.target" ];
      9 
     10     serviceConfig = {
     11       ExecStart = "${pkgs.openssh}/bin/ssh -NTg -o ServerAliveInterval=30 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=accept-new -p ${toString sshport} -i ${privatekey} -R 55013:localhost:22 ${username}@${domain}";
     12       Restart = "always";
     13       RestartSec = "10s";
     14       User = "${username}";
     15     };
     16   };
     17 
     18   environment.systemPackages = with pkgs; [ openssh ];
     19 }