Installing libssh

You can obtain the latest libssh library from https://www.libssh.org/. If you are proficient in installing C libraries, feel free to give it a go. Otherwise, read on for step-by-step instructions.

Before beginning, be sure that you've first installed the OpenSSL libraries successfully. These are required by the libssh library.

We will need CMake installed in order to build libssh. You can obtain CMake from https://cmake.org/. They provide a nice GUI installer, and you shouldn't run into any difficulties. Make sure you select the option to add CMake to your PATH during installation:

Once you have the CMake tool and the OpenSSL libraries installed, navigate to the libssh website to download the libssh source code. At the time of writing, Version 0.8.7 is the latest, and it is available from https://www.libssh.org/files/0.8/. Download and extract the libssh source code.

Take a look at the included INSTALL file.

Now, open a command window in the libssh source code directory. Create a new build folder with the following commands:

mkdir build
cd build

Keep this command window open. We'll do the build here in a minute.

Start CMake 3.14.3 (cmake-gui) from the start menu or desktop shortcut.

You need to set the source code and build locations using the Browse Source... and Browse Build... buttons. This is shown in the following screenshot:

Then, click Configure.

On the next screen, select MinGW Makefiles as the generator for this project. Click Finish.

It may take a moment to process.

From the configuration options, make the following changes:

  1. Uncheck WITH_NACL
  2. Uncheck WITH_GSSAPI
  3. Change CMAKE_INSTALL_PREFIX to c:\mingw

Then, click Configure again. It will take a moment. If everything worked, click Generate.

You should now be able to build libssh.

Go back to your command window in the build directory. Use the following command to complete the build:

mingw32-make

After the build completes, use the following command to copy the files over to your MinGW installation:

mingw32-make install

You can try building ssh_version.c from Chapter 11, Establishing SSH Connections with libssh, to test that everything is installed correctly. It should look like the following: