As @RalphRönnquist mentions in a comment, this can be achieved using
sudo apt-get install synergy
It should be installed on both computers, then the computer to be controlled runs the client (
synergyc), and the computer which should share its keyboard/mouse starts synergy server, which then has to be configured (via a GUI) to let the client computer to connect, and define where the area occupied by the remote screen is located on the extended desktop.
There are comprehensive guides explaining the process in details, e.g. this one for a Raspberry Pi.