Ubuntu Server Operations

Make sure auto-updates are enabled

apt install unattended-upgrades
#dpkg -l | grep  unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades

or do it manually,

date | mailx -s `hostname` root
mailq
cd /etc/apt/apt.conf.d/

cp -pi 50unattended-upgrades ~/50unattended-upgrades.dist
cat ../sources.list
vi 50unattended-upgrades

Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        "${distro_id}ESM:${distro_codename}";
        "${distro_id}:${distro_codename}-updates";
        "${distro_id}:${distro_codename}-proposed";
};

Unattended-Upgrade::Mail "root";

cp -pi 20auto-upgrades ~/20auto-upgrades.dist
vi 20auto-upgrades

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "1";
APT::Periodic::Unattended-Upgrade "1";

systemctl status unattended-upgrades
systemctl restart unattended-upgrades

Deal with left-over configurations

cat > ~/PURGE <<-EOF
apt autoremove
dpkg -l | grep ^rc
echo clean this all up?
dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg --purge
EOF
chmod +x ~/PURGE
./PURGE

Purge old kernels

Do you have disk space problems on /boot/?

df -h

see what you have now

uname -r
ls -lhF /boot/vmlinuz*

select the kernels you wanna get rid of and e.g.

dpkg -l | grep 5.4.0-37 | awk '{print $2}'
dpkg -l | grep 5.4.0-37 | awk '{print $2}' | xargs dpkg --purge

double-check

dpkg -l | grep kernel | awk '{print $2}'
dpkg -l | grep linux | awk '{print $2}'

obsolete

#dpkg -l | grep -E 'linux-(image|headers|extra)' | grep ^i

#apt install byobu
#purge-old-kernels

Cleaning-up

apt autoremove --purge

New Ubuntu release

lsb_release -a
df -h
dpkg -l | grep ^ rc
apt update
apt full-upgrade
apt autoremove
dpkg -l | grep ^ rc
do-release-upgrade

iptables -I INPUT -p tcp --dport 1022 -j ACCEPT

make sure grub is in place,

update-grub2

make sure there’s a few bytes left for the system to start fine,

df -h

and reboot,

reboot

Additional notes

clearing-up unwanted package repos

find the repo you don’t want

ls -lF /etc/apt/sources.list.d/ | grep -v ubuntu_dists
ls -lF /usr/share/keyrings/ | grep -v ubuntu-
ls -lhF /var/lib/apt/lists/ | grep -v ubuntu_dists

find packages which belong to a repo and get rid of those

grep ^Package /var/lib/apt/lists/dl.jami.net_nightly_ubuntu*
apt purge ...
apt autoremove --purge

e.g. for riot.im and jitsi

grep ^Package /var/lib/apt/lists/packages.riot.im_debian_dists_default_* | awk '{print $NF}' | sort -u | xargs apt -y purge
grep ^Package /var/lib/apt/lists/download.jitsi.org_stable_* | awk '{print $NF}' | sort -u | xargs apt -y purge

get rid of the now-unused repos here e.g. jami

rm -f /etc/apt/sources.list.d/jami.list*
rm -f /usr/share/keyrings/jami-archive-keyring.gpg
rm -f /var/lib/apt/lists/dl.jami.net_nightly_ubuntu*

revert to the default set of packages

draft/untested

Revert to default installed pkgs,

dpkg --get-selections >output
dpkg --set-selections <output
apt-get dselect-upgrade

Resources

AutomaticSecurityUpdates https://help.ubuntu.com/community/AutomaticSecurityUpdates

UnattendedUpgrades https://wiki.debian.org/UnattendedUpgrades

Ubuntu 16.04: Auto apt update and apt upgrade https://www.hiroom2.com/2016/05/18/ubuntu-16-04-auto-apt-update-and-apt-upgrade/

Ubuntu 18.04 remove all unused old kernels https://www.cyberciti.biz/faq/ubuntu-18-04-remove-all-unused-old-kernels/


GUIDES | LECTURES | BENCHMARKS | SMTP HEALTH