Tor Middle/Guard relay Debian

Good Bad ISPs
I am running one relay at netcup and one at terrhost

Installation as root
$ su

SSH: Change the default port
$ sudo nano /etc/ssh/sshd_config
$ Port 22 mit dem gewünschten SSL Port Port xxx ersetzen und # entfernen nicht vergessen
Save and exit (CTRL+O, CTRL+X)
$ sudo service ssh restart

Install Fail2ban
$ sudo apt install fail2ban

Config fail2ban

Install ufw firewall
$ apt install ufw
Config ufw
allow all tor ports + ssh (new ssh port)

Install tor

Enable Automatic Software Updates
$ apt-get install unattended-upgrades apt-listchanges

Edit: /etc/apt/apt.conf.d/50unattended-upgrades
$ nano /etc/apt/apt.conf.d/50unattended-upgrades

Remove all before you add the lines below

Unattended-Upgrade::Origins-Pattern {
Unattended-Upgrade::Package-Blacklist {
Save and exit (CTRL+O, CTRL+X)

Update the file /etc/apt/apt.conf.d/20auto-upgrades with the following content
$ nano etc/apt/apt.conf.d/20auto-upgrades


APT::Periodic::Update-Package-Lists "1";
APT::Periodic::AutocleanInterval "5";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::Verbose "1";
Save and exit (CTRL+O, CTRL+X)

Update /etc/apt/apt.conf.d/50unattended-upgrades for automatic update
$ nano /etc/apt/apt.conf.d/50unattended-upgrades


Unattended-Upgrade::Automatic-Reboot "true";
Save and exit (CTRL+O, CTRL+X)

Update repository
$ apt install apt-transport-https

Create tor.list
$ touch /etc/apt/sources.list.d/tor.list

Edit tor.list
$ nano /etc/apt/sources.list.d/tor.list

deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] main
deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] main
Save and exit (CTRL+O, CTRL+X)
Replace with your Operating System codename.
Run lsb_release -c or cat /etc/debian_version to check the Operating System version.

Install gpg
$ apt install gpg

Then add the gpg key used to sign the packages by running the following command at your command prompt
$ wget -qO- | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null

Update and install tor debian keyring
$ apt update
$ apt install tor

Install tor
$ apt install tor

Edit torrc
$ nano /etc/tor/torrc

Nickname myNiceRelay # Change "myNiceRelay" to something you like
ContactInfo your@e-mail # Write your e-mail and be aware it will be published
ORPort 443 # You might use a different port, should you want to
ExitRelay 0
SocksPort 0
Save and exit (CTRL+O, CTRL+X)

My torrc

Nickname xxx
ContactInfo email: xxx fingerprint: xxx matrix: xxx
MyFamily xxx,xxx
ORPort 443
ControlPort 9051
DirPort 9034
RelayBandwidthRate 120 MBits
RelayBandwidthBurst 480 MBits
ExitRelay 0
SocksPort 0

6: Optional: Limiting bandwidth usage (and traffic)
Because i have 120TB bandwidth
I have 120TB 60TB for download and 60TB for uplaod
RelayBandwidthBurst is 4x RelayBandwidthRate
Show Hosting Bandwidth Converter

Restart daemon
$ systemctl restart tor@default

Tor log
$ sudo journalctl -e -u tor@default
close log press q

Install nyx for monitoring
$ apt install nyx
use sudo as normal user
If you change torrc press 2*x for updating nyx

Backup tor identity keys

After your initial installation and start of the tor daemon it is a good idea to make a backup of your relay's long term identity keys. They are located in the "keys" subfolder of your DataDirectory (simply make a copy of the entire folder and store it in a secure location). Since relays have a ramp-up time it makes sense to back up the identity key to be able to restore your relay's reputation after a disk failure - otherwise you would have to go through the ramp-up phase again. Only do this if you have a very secure place for your keys as if stolen, these keys could theoretically allow traffic decryption or impersonation.
Default locations of the keys folder:

Debian/Ubuntu: /var/lib/tor/keys

Backup tor keys
$ sudo -su
$ cd /var/lib/
$ tar -cvf tor.tar.gz tor
$ mv tor.tar.gz tor ../../home/your_user
now you can download via ftp