ESM 401 Unauthorized error on Ubuntu 16.04

Solution 1:

Two ways exist depending on currently running Ubuntu version.

(a) Ubuntu 16.04 LTS as currently running version

You have to backup your sources.list by

sudo mv /etc/apt/sources.list ~/
sudo mv /etc/apt/sources.list.d/*.list ~/

and then fill main sources.list with correct URLs using one of commands below:

  • plain sources.list replace

    cat <<EOF | sudo tee /etc/apt/sources.list
    deb http://archive.ubuntu.com/ubuntu/ xenial-backports main universe multiverse restricted
    deb http://archive.ubuntu.com/ubuntu/ xenial main universe multiverse restricted
    deb http://archive.ubuntu.com/ubuntu/ xenial-updates main universe multiverse restricted
    deb http://security.ubuntu.com/ubuntu/ xenial-security main universe multiverse restricted
    EOF
    
  • using add-apt-repository

    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ xenial-backports main universe multiverse restricted"
    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ xenial main universe multiverse restricted"
    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ xenial-updates main universe multiverse restricted"
    sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu/ xenial-security main universe multiverse restricted"
    

and then resume upgrade to 18.04 LTS:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get purge ubuntu-advantage-tools --autoremove
sudo rm /etc/apt/sources.list.d/ubuntu-esm-infra.list
sudo do-release-upgrade

Then check ~/*.list files from previous release and partially move the lines to /etc/apt/sources.list.

(b) Ubuntu 18.04 LTS as currently running version

You have to backup your sources.list by

sudo mv /etc/apt/sources.list ~/
sudo mv /etc/apt/sources.list.d/*.list ~/

and then fill main sources.list with correct URLs using one of commands below:

  • plain sources.list replace

    cat <<EOF | sudo tee /etc/apt/sources.list
    deb http://archive.ubuntu.com/ubuntu/ bionic-backports main universe multiverse restricted
    deb http://archive.ubuntu.com/ubuntu/ bionic main universe multiverse restricted
    deb http://archive.ubuntu.com/ubuntu/ bionic-updates main universe multiverse restricted
    deb http://security.ubuntu.com/ubuntu/ bionic-security main universe multiverse restricted
    EOF
    
  • using add-apt-repository

    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ bionic-backports main universe multiverse restricted"
    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ bionic main universe multiverse restricted"
    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ bionic-updates main universe multiverse restricted"
    sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu/ bionic-security main universe multiverse restricted"
    

and then install all necessary upgrades by:

sudo apt-get purge ubuntu-advantage-tools --autoremove
sudo rm /etc/apt/sources.list.d/ubuntu-esm-infra.list

sudo apt-get update
sudo apt-get upgrade

Then check ~/*.list files from previous release and partially move the lines to /etc/apt/sources.list while replacing xenial with bionic.