Re: ssh sudo and stty -echo (514 Views)
Reply
Super Advisor
Belinda Dermody
Posts: 352
Registered: ‎05-14-1996
Message 1 of 6 (514 Views)

ssh sudo and stty -echo

Here is a sample of what I am trying to do

#!/bin/sh -xv

ssh backupserv2 stty -echo

sudo find /nsr -mtime -2 -exec ls -l {} \;

stty echo

exit


=========================================
I am running a script on one platform it does a ssh command over to another system and runs the same script which does a find command with sudo (there are files sub directories that have restrictions), but the sudo comes back and prompts for the password but when the user types in the password it is in clear text so I have been playing around with the stty -echo command I get the following error

+ echo Sudo will ask you for a passwd use your login passwd
+ [ backupserv1 = backupserv1 ]
+ stty -echo
stty: : Invalid argument
+ sudo find /nsr -mtime -7 -type f -print

Anyone know of a trick that I can hide the keying in of the password.
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 2 of 6 (514 Views)

Re: ssh sudo and stty -echo

Latest sudo versions support -S option. It accepts the password from std. input. Also you can as follows, but this has security risk involved. At most you can have read only access for a file.

ssh "some_host" "sudo "something" < ./abc

File abc contains the password.

Anil
There is no substitute to HARDWORK
Trusted Contributor
Gordon  Morrison
Posts: 145
Registered: ‎07-28-2004
Message 3 of 6 (514 Views)

Re: ssh sudo and stty -echo

Have you tried putting the "stty -echo" in a script on the remote machine and running that script via ssh?
I think the command "ssh backupserv2 stty -echo" (as you have it above) would execute the stty -echo command on the remote host, then drop the ssh connection, so what's the point in that?
What does this button do?
Respected Contributor
Robert Bennett_3
Posts: 183
Registered: ‎01-31-2005
Message 4 of 6 (514 Views)

Re: ssh sudo and stty -echo

This is how we handle similar situations:

First off - make a file that contains the server(s) you want to work with: /roots/bin/all.sites

Second - write a simple for loop:
for i in $(cat /roots/bin/all.sites)
do
echo $i >> /tmp/sudo.txt
ssh ${i} sudo find /nsr -mtime -2 -exec ls -l {} \; >> /tmp/sudo.txt
done

caveat: I'm not sure about the sudo command part of this loop as I just copied it from your original, but something of this order should work and you should be able to view the file /tmp/sudo.txt for problems or errors.

Hope this helps

B
"All there is to thinking is seeing something noticeable which makes you see something you weren't noticing which makes you see something that isn't even visible." - Norman Maclean
Super Advisor
Belinda Dermody
Posts: 352
Registered: ‎05-14-1996
Message 5 of 6 (514 Views)

Re: ssh sudo and stty -echo

I found my own answer. On the host box prior to the ssh command to the client, I run the stty -echo after the sudo commands (the password keyin is null on the screen) on the client and I return to the host box I do the stty echo and things are back to normal. I still get the invalid arg but I redirect that to /dev/null so the display is clean throughout.
Occasional Visitor
Scottie Brown
Posts: 1
Registered: ‎06-14-2005
Message 6 of 6 (514 Views)

Re: ssh sudo and stty -echo

I just solved this problem this morning. Use ssh -t . The password is not echoed back to the terminal.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.