Automatic Security Upgrades with Unattended-upgrades Package

cat /var/log/auth.log
Aug 11 06:18:42 debug010000002015 sshd[3400]: Invalid user admin from 186.47.174.116
Aug 11 06:18:42 debug010000002015 sshd[3400]: input_userauth_request: invalid user admin [preauth]
Aug 11 06:18:43 debug010000002015 sshd[3400]: Connection closed by 186.47.174.116 port 40271 [preauth]

Install and Configure unattended-upgrades

apt update && apt install unattended-upgrades
Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. The stty program didn't work. at /usr/share/perl5/NeedRestart/UI.pm line 50.
apt -t=stretch-backports install needrestart
apt install needrestart
nano /etc/needrestart/needrestart.conf
# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
#$nrconf{restart} = 'i';
# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
$nrconf{restart} = 'a';
apt install ssmtp
dpkg-reconfigure unattended-upgrades
nano /etc/apt/apt.conf.d/50unattended-upgrades
//      "o=Debian,a=stable";
// "o=Debian,a=stable-updates";
// "o=Debian,a=proposed-updates";
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"o=Debian,n=${distro_codename}";
"o=Debian,n=${distro_codename}-updates";
Unattended-Upgrade::Mail "your_username@example.com";
Unattended-Upgrade::MailOnlyOnError "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
apt-config dump | grep Unatt

Configure the Mail Transfer Agent (MTA)

nano /etc/ssmtp/revaliases
root:your_username@example.com
nano /etc/ssmtp/ssmtp.conf
root=
mailhub=smtp.example.com:465
rewriteDomain=example.com
FromLineOverride=NO
AuthUser=your_username@example.com
AuthPass=your_password
UseTLS=YES
#UseSTARTTLS=YES
chfn -f 'Web Server 1' root
ssmtp -v your_name@example.com
[<-] 250 Message received
[->] QUIT

Test unattended-upgrades

unattended-upgrades -v
ls /var/log/unattended-upgrades/
less /var/log/unattended-upgrades/unattended-upgrades.log
less /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
uptime -s
date

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store