Why does running a specific command remotely over SSH fail?

0

1

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.

LJD200

Posted 2017-07-15T15:46:06.270

Reputation: 422

"some work and some throw a different error." - Please provide these details – Ramhound – 2017-07-15T15:48:51.037

@Ramhound Thanks for your comment. I have provided details of the error via the example of the output when running date – LJD200 – 2017-07-15T15:49:52.160

1This could be because of your PATH... try specifying the full path to psshutdown or date. – Attie – 2017-07-15T16:03:45.107

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 – 2017-07-15T16:05:22.793

1One 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 – 2017-07-15T16:06:54.230

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 – 2017-07-15T16:11:40.773

Answers

1

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...

Attie

Posted 2017-07-15T15:46:06.270

Reputation: 14 841