feat: add autossh
This commit is contained in:
parent
290524071a
commit
ecf9efc39c
5 changed files with 59 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
users/
|
||||
ssh_keys/
|
||||
secret/
|
||||
results
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ in {
|
|||
./services
|
||||
./users
|
||||
./programs
|
||||
./secret
|
||||
];
|
||||
|
||||
fileSystems = fileSystemDefinition;
|
||||
|
|
|
|||
|
|
@ -20,5 +20,9 @@ rec {
|
|||
matrix = {
|
||||
trusted_servers = [ "matrix.org" ];
|
||||
};
|
||||
autossh = {
|
||||
key_path = "/etc/auto-ssh_secrets/key";
|
||||
known_hosts = "/etc/auto-ssh_secrets/known_hosts";
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
52
services/autossh.nix
Normal file
52
services/autossh.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
net = import ../data/network.nix;
|
||||
serv = import ../data/services.nix;
|
||||
|
||||
remoteListenHost = "0.0.0.0";
|
||||
remoteListenPort = 80;
|
||||
localHost = "localhost";
|
||||
localPort = 80;
|
||||
sshHost = net.services.remoteProxy.ip;
|
||||
sshPort = 22;
|
||||
sshUser = "root";
|
||||
sshKeyPath = serv.autossh.key_path;
|
||||
trustedHostsFile = serv.autossh.known_hosts;
|
||||
in
|
||||
{
|
||||
environment.systemPackages = with pkgs; [
|
||||
autossh
|
||||
moreutils
|
||||
];
|
||||
|
||||
systemd.services.autossh-tunnel = {
|
||||
description = "Autossh Reverse SSH Tunnel";
|
||||
after = [ "network.target" "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = "root";
|
||||
Restart = "always";
|
||||
RestartSec = 10;
|
||||
|
||||
ExecStart = ''
|
||||
${pkgs.autossh}/bin/autossh \
|
||||
-N \
|
||||
-T \
|
||||
-M 0 \
|
||||
-o ServerAliveInterval=10 \
|
||||
-o ExitOnForwardFailure=yes \
|
||||
-o UserKnownHostsFile=${trustedHostsFile} \
|
||||
-R ${remoteListenHost}:${toString remoteListenPort}:${localHost}:${toString localPort} \
|
||||
-i ${sshKeyPath} \
|
||||
-p ${toString sshPort} \
|
||||
${sshUser}@${sshHost} \
|
||||
2>&1 | ${pkgs.moreutils}/bin/ts '%Y-%m-%dT%H:%M:%S%z'
|
||||
'';
|
||||
};
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
}
|
||||
|
|
@ -7,5 +7,6 @@
|
|||
./openssh.nix
|
||||
./qbittorrent.nix
|
||||
./unbound.nix
|
||||
./autossh.nix
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue