Upgrading OpenSSH server on your Ubuntu distribution manually can be necessary when the default repositories do not provide the latest version. Follow these steps to manually upgrade OpenSSH server on Ubuntu.
First, download the latest version of OpenSSH:
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz
Stop the current SSH service and remove existing OpenSSH packages:
sudo systemctl stop sshd
sudo apt-get remove openssh-server openssh-client
Update your package list and install the necessary build tools:
sudo apt update
sudo apt install -y build-essential zlib1g-dev libssl-dev libpam0g-dev libselinux1-dev libwrap0-dev libedit-dev libbsd-dev autoconf automake libtool pkg-config wget curl git
Extract the downloaded tar file and build OpenSSH:
tar zxvf openssh-9.8p1.tar.gz
cd openssh-9.8p1
./configure
make
sudo make install
Create a new systemd service file for SSH:
sudo nano /etc/systemd/system/sshd.service
Paste the following content into the file:
[Unit]
Description=OpenSSH server daemon
After=network.target
[Service]
ExecStart=/usr/local/sbin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save and close the file (ctrl+x y enter).
Reload the systemd daemon, start, and enable the SSH service:
sudo systemctl daemon-reload
sudo systemctl start sshd
sudo systemctl enable sshd
If you encounter issues, unmask the SSH service and repeat the previous step:
sudo systemctl unmask ssh
sudo systemctl daemon-reload
sudo systemctl start sshd
sudo systemctl enable sshd
Finally, check the status of the SSH service:
sudo systemctl status sshd
Manually upgrading OpenSSH server ensures you have the latest security updates and features. Make sure to regularly check for updates and apply them as needed to maintain the security of your system.