User Tools

Site Tools


computing:remote-upgrades

  • remote-upgrades
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

remote-upgrades


For remote upgrades from primary workstation, first create a file on target called apt-remote:

sudo touch /usr/local/bin/apt-remote
sudo chmod 750 /usr/local/bin/apt-remote
sudo chown $USER:$USER /usr/local/bin/apt-remote
sudo nano /usr/local/bin/apt-remote

Once that is done, put in some parameters that will provide nice feedback to you while you execute the command from primary workstation:

#!/bin/bash
echo "I am beginning";
cat /etc/motd
apt update
apt dist-upgrade
apt autoremove
apt autoclean
echo "I just finished";
echo "----->"
echo "-----> ----->"
echo "-----> -----> ----->"
echo "-----> -----> -----> ----->"
echo "-----> -----> -----> -----> -----> ... ... "
hostname
date
uname -a
echo "If there is another, I will begin that now ...";
sleep 10s

Edit sudoers so that this command can be run on target without password, (or, if your prefer, do not do this, and then you can enter the password for each target as the primary workstations script executes):

sudo nano /etc/sudoers

Add the following to the file, obviously changing “username” to the target machine's user name.

username ALL=(root) NOPASSWD: /usr/local/bin/apt-remote

Now you are ready to create the script on the primary workstation (localhost) that will pass the apt-remote script to the target workstations:

sudo touch /usr/local/bin/apt-remote-update.sh
sudo chmod 750 /usr/local/bin/apt-remote-update.sh
sudo chown $USER:$USER /usr/local/bin/apt-remote-update.sh
sudo touch /usr/local/bin/apt-remote-update.sh

In the file that opens, use the following script parameters or something similar. This script runs on the primary workstation and then executes the “sudo apt-remote” script on the target machine. Again, none of this will work if your ssh is improperly configured.

#!/bin/bash
hosts="server.com 10.55.55.9"
#run on each host
for i in $hosts;
do
  echo "I will now update" $i;
  #ssh -t $i sudo apt-remote;
  ssh -t $i screen -S aptremotescreen sudo apt-remote;
done;

If you would prefer to do these types of backups with a vpn connection (instead of port forwarding), then use something like these configurations below.

Option 1 - Using vpn connection, connect from localhost to remote host/server with ssh and screen, and then execute a script on the server that uses rsync over ssh to send its backup to target backup host on its LAN:

Use this script on your localhost: localhost.sh Use this script on the remote host that you are backing up: remote.sh

Option 2 - Using vpn connection, connect from localhost to remote host/server with ssh and screen, and then execute a script on the server that uses rsync over ssh to send its backup back to you at localhost:

Use this script on your localhost: localhost.sh

oemb1905 2020/01/27 13:18

computing/remote-upgrades.txt · Last modified: 2020/01/27 20:42 by oemb1905