问题
I am trying to create a PowerShell script to SSH into a Raspberry Pi and perform some commands. I am using Plink to SSH into the Pi over command line. However I have to SSH into the Pi user which runs in lshell. I can PuTTY into the Pi with zero issues, but when using Plink I get an error saying the command I am using is forbidden. I am trying to use su
which works when using PuTTY by not Plink.
The error I get is below:
plink : *** forbidden char/command over SSH: "su"
At line:1 char:1
+ plink -ssh pi@<IP> -pw <password> su
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (*** forbidden c... over SSH:
"su":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
This incident has been reported.
Thank you for any help you can provide.
回答1:
There are two differences when using plink ... command
comparing to logging in with PuTTY and typing command
:
plink ... command
opens an "exec" channel to run the command. While PuTTY opens "shell" channel with login shell and only the shell runs the command.plink ... command
by default opens a non-interactive session (no TTY). While PuTTY opens an interactive session (with TTY).
To test the Plink behavior in PuTTY:
- Enter the command to Connection > SSH > Remote command.
- Check Connection > SSH > TTY > Don't allocate a pseudo-terminal.
Conversely, to test PuTTY behavior in Plink, use:
echo command | plink ...
Check also Plink -T/-t switches.
This behaves as PuTTY in 2, but not in 1:
plink -t ... command
Conversely, this behaves as PuTTY in 1, but not in 2:
echo command | plink -T ...
Experiment with these to find out, what is causing your particular problem.
来源:https://stackoverflow.com/questions/46591648/executing-command-using-plink-does-not-work-but-does-in-putty