I currently have a few different services running on my home server and for simplicity, I have a single VM manage the certificates via certbot and just copy them across the network using SCP.
The ssh connections are key secured but since I'm running it automated, the keys themselves don't require a password which obviously isn't ideal.
The keys are only stored in the root account of the VM that manages certbot but I'd still like an option where the script could copy the files across without me having to essentially have an unsecured method for root access to other systems on my network if someone gained access to one of them.
Is there a way to only allow certain commands to be passed over an ssh connection without allowing it to open a shell session, or can anyone think of another way to copy the files across on my weekly cron job that wouldn't leave an option for someone to ssh across to my other machines?
My router only enables the user for certbot on a Saturday evening, which allows my VM to ssh in and run a script that disables the firewall rule that blocks port 80, runs the certbot renew command, enables the firewall rules again and disables the certbot user. I'm comfortable enough with this since there's only a maximum 15 minute window each week where the router user is enabled.
It's the copying of the certificates that's the problem as obviously with it being carried out as root, the accounts are active at all times.
#!/bin/bash
ssh [email protected] "/system script run certbotenable"
#ufw allow 80
certbot renew
#ufw delete allow 80
systemctl restart apache2
ssh [email protected] "/system script run certbotdisable"
scp /etc/letsencrypt/live/sazed.mydomain.com/cert.pem root@sazed:/etc/pve/local/pveproxy-ssl.pem
scp /etc/letsencrypt/live/sazed.mydomain.com/privkey.pem root@sazed:/etc/pve/local/pveproxy-ssl.key
scp /etc/letsencrypt/live/rashek.mydomain.com/cert.pem root@rashek:/root/ssl/fullchain.pem
scp /etc/letsencrypt/live/rashek.mydomain.com/privkey.pem root@rashek:/root/ssl//privkey.key
ssh root@sazed "service pveproxy restart"