Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

For solutions, see Script via Plink in .bat behaves differently


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...