You can set the numlock state from within an SSH session by accessing /dev/console, which requires root permission (unless you change the permissions on /dev/console
).
All of these commands assume that the user can execute sudo without a password. This is often the case when the user is in a group called "sudo" or "wheel" depending on distribution and local configuration.
# turn on numlock
sudo sh -c 'setleds +num < /dev/console'
# turn off numlock
sudo sh -c 'setleds -num < /dev/console'
It's also possible to write to the /sys entry for the device:
# Note that 'bash' is used to support the '?' glob.
# You could use 'sh' if you specified "input1."
# Turn off numlock LED (also turns off the numlock state)
sudo bash -c 'echo 0 > /sys/class/leds/input?::numlock/brightness'
# Turn on numlock LED
sudo bash -c 'echo 1 > /sys/class/leds/input?::numlock/brightness'
For the /sys approach, you don't need to spawn a sub-shell since tee
can write to the brightness file without output redirection:
# both the ? glob and > redirection happen outside the sudo process by your local shell
# Turn on
echo 1 | sudo tee /sys/class/leds/input?::numlock/brightness > /dev/null
# Turn off
echo 0 | sudo tee /sys/class/leds/input?::numlock/brightness > /dev/null
Tested on a Raspberry Pi 4 Model B rev 1.4.