Raspberry Pi

How to Update OpenSSL on Raspberry Pi

OpenSSL is a software library for implementing the SSL and TLS protocols to secure communication over other networks. Most popular programs like Apache, Postfix and PHP use it for communication as it provides them with several cryptographic algorithms (such as AES, DES), hash functions (such as SHA1, SHA2) and public key cryptography (such as RSA and DSA) for secure communication.

This article will show you how you can install the latest version of OpenSSL on your Raspberry Pi system.

How to Update OpenSSL on Raspberry Pi

The Raspberry Pi system, by default, includes the OpenSSL version “1.1.1”, an outdated version of this library. You can confirm the version of OpenSSL through the following command:

$ openssl version

The latest version of OpenSSL at the time of writing this article is “3.0.7”, which includes much better security updates and enhanced features. To update your current OpenSSL version to the latest one, follow the below-mentioned steps:

Step 1: Install Dependencies

Before beginning the installation, install some dependencies for OpenSSL through the following command:

$ sudo apt install build-essential zlib1g-dev checkinstall -y

Step 2: Change the Location

Next, change your location to “/usr/local/src” through the following command because, at this location, we are going to perform the OpenSSL installation.

$ cd /usr/local/src/

Step 3: Download OpenSSL Latest Version Source File

Go to the website to download OpenSSL latest version source file. You can use the wget command for downloading it on Raspberry Pi, as given below.

$ wget https://www.openssl.org/source/openssl-3.0.7.tar.gz

Step 4: Extract Content of OpenSSL Source File

To extract the contents of the OpenSSL source file, use the following command:

$ sudo tar -xf openssl-3.0.7.tar.gz

You can use the “ls” command to check for the directory name where the files are extracted.

Step 5: Navigate to OpenSSL Directory

Use the following command to navigate to the OpenSSL directory:

$ cd openssl-3.0.7

Step 6: Configure OpenSSL

Before installation, you must configure OpenSSL from the following command:

$ sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib

The above command sets up the path for OpenSSL, creates a shared library and enables compression using the zlib library.

Step 7: Compile the OpenSSL Files

Now, use the following command to compile the files required for installing OpenSSL on your Raspberry Pi system:

$ sudo make

Step 8: Install OpenSSL

After the compilation, you can then install OpenSSL on Raspberry Pi through the following command:

$ sudo make install

Step 9: Configure Shared Libraries for OpenSSL

OpenSSL loads the binary files from the location “/usr/local/ssl/lib” and you have to configure this path. First, navigate to the following directory:

$ cd /etc/ld.so.conf.d/

Create a configuration file through the nano editor using the following command:

$ sudo nano openssl-3.0.7.conf

Append the following location inside the file.

/usr/local/ssl/lib

Save this file using “CTRL+X” and then reload the changes through the following command:

$ sudo ldconfig -v

Step 10: Replace the Default OpenSSL Libraries

You must replace the previous default OpenSSL libraries with the new ones, but before that, you must create the files backup by running the following commands one by one.

$ sudo mv /usr/bin/openssl /usr/bin/openssl.BEKUP

$ sudo mv /usr/bin/c_rehash /usr/bin/c_rehash.BEKUP

Afterward, you have to edit the /etc/environment file:

$ sudo nano /etc/environment

Inside the file, paste the following text:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/
local/games:/usr/local/ssl/bin"

Save the file and then load the changes using the following command:

$ source /etc/environment

You can test the path through the following command:

$ echo $PATH

Once this is done, you can use the following command to ensure that OpenSSL is successfully updated on your Raspberry Pi system.

$ openssl version

Conclusion

OpenSSL is a cryptographic library used for secure communication over networks. Though it’s already installed on the Raspberry Pi system, you can update its version by following the above-mentioned steps. These steps require installing dependencies, changing the location, downloading the source file, and setting up the environment.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.