Hi,
I am interested in running scripts using the plink.exe file. We have enabled root login over ssh on all our esx servers so do I need to add the following file to our suders ?
...
root ALL=(ALL) NOPASSWD: ALL
...
Or should the script just run because we are running as root? I have not tried this yet just in case its a bad idea to use the following line..
I have tried to run some scripts and it fails here :
Disconnected: User aborted at host key verification
At :line:1 char:12
+ C:\plink.exe <<<< -v -batch -pw password1 "sudo -u root cat /etc/vmware/esx.conf"
Is the above error because of the password prompt? I have connected to the server before...
Thanks
Packetboy.
The PuTTY tools (including plink) cache host keys in the registry.
The first time you connect to a server, it will ask you if you trust the connection.
If you answer <yes>, the host's key is stored in the registry and future calls will not ask the same question anymore.
I suspect this is the first time you connect to the host with any of the PuTTY commands and since plink is called in "batch" mode it can't show you the question.
The easiest solution is to connect once interactively (with putty.exe for example) to the host and let it store the host's key in the registry.
Btw, if you allow root SSH connections (which is not advisable for security reasons) there is no need to configure sudo on the host.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The PuTTY tools (including plink) cache host keys in the registry.
The first time you connect to a server, it will ask you if you trust the connection.
If you answer <yes>, the host's key is stored in the registry and future calls will not ask the same question anymore.
I suspect this is the first time you connect to the host with any of the PuTTY commands and since plink is called in "batch" mode it can't show you the question.
The easiest solution is to connect once interactively (with putty.exe for example) to the host and let it store the host's key in the registry.
Btw, if you allow root SSH connections (which is not advisable for security reasons) there is no need to configure sudo on the host.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you ssh to a host the first time, plink will ask you to accept the key.
There is an easy way to get around this, use this dummy line:
"echo Y | plink.exe -l root -pw Password esxhost1.example.com exit"
Before using the plink.exe...as LuCD said ...we first logged onto each interactively once before using plink
Since the scipts was run as root it all just worked....
Hi everyone thanks for the comments. However I have logged into this server before... So the host key is already in the registry because when I log in using putty it does not prompt me to trust the key..
I am however running my script from within PowerGUI... Could that run it differently? I run all my scripts from powergui because I like using an IDE...
Thanks,
packetboy.
Update: Ok this is weird if I connected with Putty it did not prompt me about the host key.. .But then when I manually connected using plink.exe it did prompt me! So I accepted and now the script logs in but now I am getting a "Unable to read from standard input" error but I think thats something different...
So thanks for the help !
Did you try running your script from the PowerCLI prompt ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I've seen it too. There is a different behaviour running a powershell script using the plink.exe tool to log to a remote server but I've no idea why. What I'm doing is I'm writing the script in PowerGUI and then execute it in powershell console!
wow you guys are quick at replying ! So it was not working in the vi toolkit window either.. but now it works since i manully connected with plink in both the vi toolkit window and powergui... but like i said i think there is something wrong with my script syntax now...
Unable to read from standard input
At :line:1 char:12
+ C:\plink.exe <<<< -v -batch -pw Password "cat /etc/vmware/esx.conf"
hey thats weird!! you are right ! i get the "unable to read from standard input" error when running the script in powergui ( an empty esx.conf file is created in my temp dir) but then if i run the script from the vitoolkit window it works !!!
any ideas why ? would be cool if i didnt need to jump out of powergui
As I said I haven't figure out why. It seems like some powergui issue. But as you see even with the error it works. You can try to set $ErrorActionPreference = SilentlyContinue and run the script in PowerGui again. It should hide the error and do the rest of the script!
How do you execute the plink command?
I always use invoke-expression.