Skip to content

Instantly share code, notes, and snippets.

@allyunion
Created July 29, 2024 02:58
Show Gist options
  • Save allyunion/f4c294bfec6570d78e3a7c5e3fb61f34 to your computer and use it in GitHub Desktop.
Save allyunion/f4c294bfec6570d78e3a7c5e3fb61f34 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# Variables
OPENSSL_VERSION="3.3.1"
OPENSSL_TAR="openssl-${OPENSSL_VERSION}.tar.gz"
OPENSSL_DIR="openssl-${OPENSSL_VERSION}"
OPENSSL_URL="https://www.openssl.org/source/${OPENSSL_TAR}"
OPENSSH_VERSION="9.8p1"
OPENSSH_TAR="openssh-${OPENSSH_VERSION}.tar.gz"
OPENSSH_DIR="openssh-${OPENSSH_VERSION}"
OPENSSH_URL="https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/${OPENSSH_TAR}"
# Install build dependencies
sudo apt update
sudo apt install -y build-essential fakeroot devscripts zlib1g-dev libssl-dev libpam0g-dev checkinstall wget
# Download OpenSSL if not already downloaded
if [ ! -f "${OPENSSL_TAR}" ]; then
wget --no-check-certificate "${OPENSSL_URL}"
fi
# Extract and build OpenSSL
tar -xzf "${OPENSSL_TAR}"
cd "${OPENSSL_DIR}"
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make
sudo make install
# Create configuration file for dynamic linker
echo "/usr/local/openssl/lib" | sudo tee /etc/ld.so.conf.d/openssl.conf
# Update the library path
sudo ldconfig -v
# Go back to the parent directory
cd ..
# Download OpenSSH if not already downloaded
if [ ! -f "${OPENSSH_TAR}" ]; then
wget --no-check-certificate "${OPENSSH_URL}"
fi
# Extract and prepare OpenSSH
tar -xzf "${OPENSSH_TAR}"
cd "${OPENSSH_DIR}"
# Set environment variables to use the specific OpenSSL installation
export CFLAGS="-I/usr/local/openssl/include"
export LDFLAGS="-L/usr/local/openssl/lib"
# Configure the build to use the newly installed OpenSSL and install to /usr/local/openssh
./configure --with-ssl-dir=/usr/local/openssl --with-ssl-engine --prefix=/usr/local/openssh
make
sudo make install
# Create symbolic links in /usr/local/bin and /usr/local/sbin
sudo ln -sf /usr/local/openssh/bin/scp /usr/local/bin/scp
sudo ln -sf /usr/local/openssh/bin/sftp /usr/local/bin/sftp
sudo ln -sf /usr/local/openssh/bin/ssh /usr/local/bin/ssh
sudo ln -sf /usr/local/openssh/bin/ssh-add /usr/local/bin/ssh-add
sudo ln -sf /usr/local/openssh/bin/ssh-agent /usr/local/bin/ssh-agent
sudo ln -sf /usr/local/openssh/bin/ssh-keygen /usr/local/bin/ssh-keygen
sudo ln -sf /usr/local/openssh/bin/ssh-keyscan /usr/local/bin/ssh-keyscan
sudo ln -sf /usr/local/openssh/sbin/sshd /usr/local/sbin/sshd
# Verify Installation
echo "Verifying installation..."
ssh -V
openssl version
echo "OpenSSH and OpenSSL have been successfully installed and linked."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment