Preamble: As observed in the question, openssl installs by default into
/usr/local/ssl. My recommendation is to use
./config --prefix=/usr/local shared (notice the space before "shared") so that it installs there (and builds the shared library,
libssl), rather than its own private subdirectory. If you do not do this, you will have to add a file to
/usr/local/ssl/lib in it (see below for the significance of
/etc/ld.so.conf.d files), and add
You will need to run
make install to add the libraries to the linker cache. If that doesn't work, read on.
make install probably by default went to
/usr/local, which should take precedence but may not. You can thus leave your distro's openssl install to avoid messing around with the package manager and prereqs, but still use your own locally built version as the default. To check:
ldd $(which ssh) | grep libssl
If you get no output, your
ssh was statically linked and needs to be rebuilt (see Anton's answer). Otherwise, this should point to your
/usr/local version. If it points to something else:
ldconfig -p | grep libssl
/usr/local version should be shown, but after some other one. If so, skip down to "/usr/local/lib does not have precedence" below. If not, make sure
/usr/local is in the linker path generally:
ldconfig -p | grep "/usr/local"
grep -r "/usr/local" /etc/ld.so.conf.d. If that is not there, add a file to
00-local.conf with one line:
ldconfig (no switches) and go through this again.
/usr/local/lib does not have precedence
Find the linker cache config file where the path is added:
grep -r "/usr/local" /etc/ld.so.conf.d
If it's not there, you'll have to add a file as explained above. Presuming it is, the problem is the files are processed lexicographically. E.g., if the content of
addtheselibraries.conf contains, e.g.
/usr/lib,1 then the latter will take precedence. If the
/usr/local/lib file doesn't contain anything else, just rename it with something which will supersede the other files; numbers go first so
000-whatever is good.
Because you have complete control over
/usr/local/lib, it should take precedence over any paths used by the distro package manager (and usually does).
1. /usr/lib is a default compiled into the linker, but it and other standard system places (/lib, etc) are added last, which allows you to supersede them. Because of these, sometimes (e.g.)
/usr/lib is added to a .conf file in order to make it supersede some other .conf file.