Created
January 8, 2025 03:50
-
-
Save troke12/47aee0909369ed605854c155c99f189d to your computer and use it in GitHub Desktop.
update ssh script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit on error | |
set -e | |
# Variables | |
OPENSSH_VERSION="9.8p1" | |
WORKDIR="/usr/local/src" | |
PREFIX="/usr/local/openssh" | |
# Update and install dependencies | |
echo "Updating system and installing dependencies..." | |
sudo apt update && sudo apt upgrade -y | |
sudo apt install -y build-essential zlib1g-dev libssl-dev libpam0g-dev wget curl | |
# Create working directory | |
if [ ! -d "$WORKDIR" ]; then | |
echo "Creating working directory: $WORKDIR" | |
sudo mkdir -p "$WORKDIR" | |
fi | |
cd "$WORKDIR" | |
# Download OpenSSH source code | |
echo "Downloading OpenSSH $OPENSSH_VERSION..." | |
wget -q "https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-$OPENSSH_VERSION.tar.gz" | |
echo "Extracting OpenSSH $OPENSSH_VERSION..." | |
tar -xf "openssh-$OPENSSH_VERSION.tar.gz" | |
cd "openssh-$OPENSSH_VERSION" | |
# Configure and compile OpenSSH | |
echo "Configuring OpenSSH..." | |
./configure --prefix="$PREFIX" --sysconfdir="/etc/ssh" --with-pam --with-zlib --with-ssl-engine | |
echo "Compiling OpenSSH..." | |
make -j$(nproc) | |
# Install OpenSSH | |
echo "Installing OpenSSH..." | |
sudo make install | |
# Backup existing SSH configuration and binaries | |
echo "Backing up existing SSH configuration and binaries..." | |
if [ -f /usr/sbin/sshd ]; then | |
sudo mv /usr/sbin/sshd /usr/sbin/sshd.bak | |
fi | |
if [ -f /usr/bin/ssh ]; then | |
sudo mv /usr/bin/ssh /usr/bin/ssh.bak | |
fi | |
# Replace existing binaries with the new version | |
echo "Replacing existing SSH binaries with the new version..." | |
sudo ln -sf "$PREFIX/sbin/sshd" /usr/sbin/sshd | |
sudo ln -sf "$PREFIX/bin/ssh" /usr/bin/ssh | |
sudo ln -sf "$PREFIX/bin/scp" /usr/bin/scp | |
sudo ln -sf "$PREFIX/bin/sftp" /usr/bin/sftp | |
sudo ln -sf "$PREFIX/bin/ssh-keygen" /usr/bin/ssh-keygen | |
sudo ln -sf "$PREFIX/bin/ssh-keyscan" /usr/bin/ssh-keyscan | |
sudo ln -sf "$PREFIX/bin/ssh-add" /usr/bin/ssh-add | |
sudo ln -sf "$PREFIX/bin/ssh-agent" /usr/bin/ssh-agent | |
# Restart SSH service | |
echo "Restarting SSH service..." | |
sudo systemctl restart sshd | |
# Verify installation | |
echo "Verifying OpenSSH installation..." | |
/usr/sbin/sshd -V | |
/usr/bin/ssh -V | |
echo "OpenSSH $OPENSSH_VERSION installation completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment