I am creating two Bash scripts on my Raspberry Pi, which is running the default Debian-based Linux distro: one to sleep my desktop computer, and one to shut it down.
The script to shutdown the computer works fine and its contents are:
sshpass -p "MYPASSWORD" ssh administrator@MYCOMPUTERNAME "shutdown /s"
My desktop is running Windows 10 and the built-in SSH server that comes with Windows 10.
When I try to run the script to sleep my computer, however, I am presented with the output:
Packet integrity error (165 bytes remaining) at ../channels.c:2401 Disconnecting: Packet integrity error.
The contents of this script are:
sshpass -p "MYPASSWORD" ssh administrator@MYCOMPUTERNAME "psshutdown /d"
'psshutdown' refers to the Windows Sysinternals utility.
Strangely, running the command
psshutdown /d from an Administrator command prompt, when sitting at my desktop, successfully sleeps my computer. It also works if I connect via SSH from the Pi without specifying a command to run once connected, i.e.
sshpass -p "MYPASSWORD" ssh administrator@MYCOMPUTERNAME, and then run the
psshutdown /d command. Running the same command as in the script directly in Bash fails with the same output as above.
Interestingly, when trying to run some other commands in the same way as in the sleep script, some work and some throw a different error. For example,
sshpass -p "MYPASSWORD" ssh administrator@MYCOMPUTERNAME "whoami" works fine and returns the correct output but
sshpass -p "MYPASSWORD" ssh administrator@MYCOMPUTERNAME "date" produces the output
exec request failed on channel 0
What is causing the sleep script to fail and how can I resolve the issue to successfully run the command over SSH?
Note: I understand it is not ideal to store the SSH password in plain text in a script file but setting up key-based authentication on the built-in SSH server is a challenge for another day.