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.

  • "some work and some throw a different error." - Please provide these details – Ramhound Jul 15 '17 at 15:48
  • 1
    This could be because of your PATH... try specifying the full path to psshutdown or date. – Attie Jul 15 '17 at 16:03
  • 1
    @Attie Thanks for your comment. I have also already tried specifying the full path to psshutdown. I should have mentioned that in the question - I'll edit it now. – LJD200 Jul 15 '17 at 16:05
  • 1
    One other thought re psshutdown... if it's working, then it's very possible that the windows network stack is being suspended before the SSH session completes - hence the Packet integrity error... – Attie Jul 15 '17 at 16:06
  • 1
    @Attie Although I'm certain that I'd already tried specifying the full path to psshutdown, when doing so again, the script ran successfully and my PC slept! Thanks for your help. That was a very strange issue. – LJD200 Jul 15 '17 at 16:11

This is likely due to your PATH... try specifying the full path to psshutdown or date.

The SSH session, without a shell or PTY will most likely have a very basic PATH set...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.