Last active
July 25, 2024 17:56
-
-
Save allyunion/411c00d878c5195d6a20b6937fe29ef9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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 dh-make | |
# 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 | |
# Create a Debian package for OpenSSL | |
sudo checkinstall --pkgname=openssl --pkgversion="${OPENSSL_VERSION}" --backup=no --deldoc=yes --fstrans=no --default | |
# 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}" | |
# Configure the build to use the newly installed OpenSSL | |
./configure --with-ssl-dir=/usr/local/openssl --with-ssl-inc=/usr/local/openssl/include --with-ssl-lib=/usr/local/openssl/lib | |
# Prepare the source for packaging | |
dh_make --multi --yes -f "../${OPENSSH_TAR}" | |
# Create debian/control file | |
cat <<EOF > debian/control | |
Source: openssh | |
Section: net | |
Priority: optional | |
Maintainer: Jason Y. Lee <[email protected]> | |
Build-Depends: debhelper (>= 9), libssl-dev, zlib1g-dev, libpam0g-dev | |
Standards-Version: 3.9.8 | |
Homepage: https://www.openssh.com/ | |
Package: openssh-client | |
Architecture: any | |
Depends: \${shlibs:Depends}, \${misc:Depends} | |
Description: secure shell (SSH) client, for secure access to remote machines | |
OpenSSH is a free implementation of the Secure Shell protocol. | |
This is the portable version of OpenSSH, a free implementation of the Secure Shell protocol | |
as specified by the IETF secsh working group. | |
Package: openssh-server | |
Architecture: any | |
Depends: \${shlibs:Depends}, \${misc:Depends}, openssh-client | |
Description: secure shell (SSH) server, for secure access from remote machines | |
OpenSSH is a free implementation of the Secure Shell protocol. | |
This is the portable version of OpenSSH, a free implementation of the Secure Shell protocol | |
as specified by the IETF secsh working group. | |
EOF | |
# Create debian/openssh-client.install file | |
cat <<EOF > debian/openssh-client.install | |
usr/bin/scp | |
usr/bin/sftp | |
usr/bin/ssh | |
usr/bin/ssh-add | |
usr/bin/ssh-agent | |
usr/bin/ssh-keygen | |
usr/bin/ssh-keyscan | |
EOF | |
# Create debian/openssh-server.install file | |
cat <<EOF > debian/openssh-server.install | |
usr/sbin/sshd | |
usr/libexec/sftp-server | |
etc/ssh/sshd_config | |
EOF | |
# Build the OpenSSH packages | |
dpkg-buildpackage -rfakeroot -b | |
# Install the OpenSSH client and server packages | |
cd .. | |
sudo dpkg -i "openssh-client_${OPENSSH_VERSION}-1_amd64.deb" | |
sudo dpkg -i "openssh-server_${OPENSSH_VERSION}-1_amd64.deb" | |
# Verify Installation | |
echo "Verifying installation..." | |
ssh -V | |
openssl version | |
echo "OpenSSH and OpenSSL have been successfully installed and packaged." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment