When I first tried to install the Azure CLI on my Linux Mint 19 machine, I thought it would be simple just follow the manual instructions from Microsoft, But the process quickly threw me into error land. Let me walk you through what happened, what I learned, and how I fixed it.
The Error That Stopped Me
The official instructions started with this line:
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
But instead of installing smoothly, I hit this error:
openssh-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
Naturally, I tried the usual:
sudo dpkg --configure -a
sudo apt-get install -f
but no luck. Both commands failed with a service error:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code)
Process: 22323 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)
At this point, Azure CLI wasn’t even the real problem the openssh server package was broken, and because dpkg
aborted, apt
couldn’t proceed.
What Was Really Happening
That cryptic message:
E: Sub-process /usr/bin/dpkg returned an error code (1)
basically means: “a package failed during post-install configuration.”
In my case, openssh-server
was the culprit. Its post-install script runs:
/usr/sbin/sshd -t
That command checks the SSH configuration for errors. Since it failed with status 255
, dpkg
refused to continue. Until I fixed SSH, I couldn’t install anything.
Common Causes of sshd -t = 255
Through trial and error (and a bit of digging), I discovered these are the usual suspects:
- A broken
/etc/ssh/sshd_config
file (typos, invalid directives, duplicates). - Missing or unreadable SSH host keys (
/etc/ssh/ssh_host_*
). - Port conflicts (something else already listening on port 22).
- Wrong permissions or ownership on config or key files.
My Quick Fix
Here’s how I fixed it, in order. You can follow these too:
# 1) Test sshd config
sudo /usr/sbin/sshd -t -f /etc/ssh/sshd_config || echo "sshd_config has an error"
# 2) Regenerate host keys if missing
sudo ssh-keygen -A
# 3) Correct permissions
sudo chown root:root /etc/ssh/sshd_config
sudo chmod 644 /etc/ssh/sshd_config
sudo chmod 600 /etc/ssh/ssh_host_*_key 2>/dev/null || true
sudo chmod 644 /etc/ssh/ssh_host_*_key.pub 2>/dev/null || true
# 4) Check if port 22 is in use
sudo ss -ltnp | grep ':22' || true
# 5) Reset sshd_config to default (backup first!)
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%s)
sudo apt-get -y --reinstall install openssh-server
sudo cp /usr/share/openssh/sshd_config /etc/ssh/sshd_config 2>/dev/null || true
# 6) Retest and restart SSH
sudo /usr/sbin/sshd -t -f /etc/ssh/sshd_config
sudo systemctl enable --now ssh
# 7) Finally unstick apt/dpkg
sudo dpkg --configure -a
sudo apt-get -f install
After this, apt worked again. That felt like a win!
Installing Azure CLI Properly
Once SSH was fixed, I could finally continue with the Azure CLI installation.
# 1) Install dependencies
sudo apt-get update
sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg
# 2) Add Microsoft repo for Ubuntu 18.04 (Mint 19 base = bionic)
curl -sL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ bionic main" | \
sudo tee /etc/apt/sources.list.d/azure-cli.list
# 3) Update and install CLI
sudo apt-get update
sudo apt-get install -y azure-cli
# 4) Verify install
az version
If you’re on Mint 20/21, just swap bionic
with focal
or jammy
.
Practice Utilities I Use
To make sure everything was solid, I tested a few things:
Check SSH service health
systemctl status ssh --no-pager
journalctl -u ssh -b --no-pager | tail -200
Confirm Azure CLI works
az login
az account show --output table
az group list --output table
Cleanup if needed
sudo apt-get remove -y azure-cli
sudo rm -f /etc/apt/sources.list.d/azure-cli.list
sudo apt-get update
Final Thought
When I first tried to install the Azure CLI on my Linux Mint 19 machine, I thought it would be simple—just follow the manual instructions from Microsoft, right? But the process quickly threw me into error land. Let me walk you through what happened, what I learned, and how I fixed it.