Executing command using Plink does not work, but does in PuTTY

对着背影说爱祢 提交于 2021-02-08 02:07:35

问题


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:

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

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

  1. Enter the command to Connection > SSH > Remote command.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!