plink => su: must be run from a terminal

Posted on 2013-06-05
Last Modified: 2013-06-06

I need to reboot a linux server from Windows.

My script doesn't work.

echo n | putty -ssh -t -noagent  %LOGIN%@%IP% -pw %PASSWORD% -m

Open in new window

echo 123456 | su - reboot

Open in new window

I can't change linux parameters.
PermitRootLogin No
My user isn't sudoers

i have root password & user password

Thanks for your help !
Question by:PepperRed
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
LVL 68

Expert Comment

ID: 39225245

su -  -c reboot

ping ... in your script is useless, it will not be processed after "reboot"

What should these "echo n"  and "echo 123456" be good for?

Finally. I assume you meant to write "plink" instead of "putty" in the code you posted?
LVL 21

Expert Comment

ID: 39225721
I don't think you can pass in plain text for password with su.

Any reason why you are not using sudoer? You can pass in a password argument with plink if you have sudoer setup. One line in batch. For example -

plink -pw bad user@server sudo /usr/bin/reboot
LVL 19

Expert Comment

ID: 39227257
I assume that the "echo 123456" in is for the root password.  Couple of problems with that - su doesn't read the password from stdin, and it can't be run in a pipeline like that.

You need to use expect:
expect <<EOF
spawn su - -c reboot
expect sword
send "123456\r"
expect eof

Open in new window

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.


Author Comment

ID: 39227282
ping command is just to see the error "su: must be run from a terminal"

With plink or putty in my script, the error is the same.

Don't use sudoer is my company policy.

I try su - -c reboot but : "su: must be run from a terminal"

As Mazdajai say it, i think i can't pass in plain text for password with su.

Do you know an other method to reboot a linux from Windows with my constraints

LVL 21

Expert Comment

ID: 39227325
Passing plaintext password with su is the problem. I don't see this is possibile with your contriant.
LVL 34

Accepted Solution

Duncan Roe earned 200 total points
ID: 39227358
This is the classic problem that expect was designed to solve. There is a version of expect for Windows, but it's not free and I don't remember the URL - Google will find it.
However - and this is free - expect is supported under Cygwin.
So if you install Cygwin and be sure to include expect (not part of the minimal install) then you can write an expect script to do what you want. Post back if you need help in writing the script.
LVL 68

Expert Comment

ID: 39227395
Back to the original issue ("su: must be run from a terminal"):

The "-t" flag of plink (not putty!) should take care of allocating a pseudo tty.

Apart from all the other good suggestions above: "su - -c ..." should work and ask you for a password if you really used "plink" and its "-t" flag.
Try without "echo 123456 | "  (If you're still interested, that is).

Author Comment

ID: 39227803
I try yours differents solutions with no success and finally i have success with expect script.

My expect script which i launch from a batch :


expect <<EOF
spawn "C:\\Program Files\\PuTTY\\plink.exe" -ssh -t -noagent  test@ -pw password

expect sword
send "su -\r"
       expect {
           "Password: " {send "123456\r"}
expect sword
send "reboot\r"

expect eof

Open in new window

Thanks all

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Google Chromebook AV solutions 5 75
Assignment from incompatible pointer type? 2 39
Linux kernel panic ext3-fs error 14 33
AWS Linux EC2 question on group 7 22
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Fine Tune your automatic Updates for Ubuntu / Debian
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question