--- keywords: - IT --- # systemd cheat sheet ## ssh systemd rerverse shell as service - persistent reverse SSH connection with systemd ``` -g Allows remote hosts to connect to local forwarded ports -N Do not execute a remote command -T Disable pseudo-terminal allocation -o Used to give options in the format used in the configuration file (man ssh_config) ServerAliveInterval Interval in seconds to ping the server while connection has been inactive ExitOnForwardFailure Whether to terminate the connection if it cannot set up all requested port forwards -R Forward given remote TCP port (22221) to the local port (22) -v Verbose mode. More v's increase verbosity. ``` the specific unit file to place under: `/etc/systemd/system/ssh-reverse.service` ``` [Unit] Description=Reverse SSH connection After=network.target [Service] Type=simple ExecStart=/usr/bin/ssh -vvv -g -N -T -o "ServerAliveInterval 10" -o "ExitOnForwardFailure yes" -R 22221:localhost:22 {target_IP} Restart=always RestartSec=5s [Install] WantedBy=default.target ``` credits belongs to blog.stigok.com