problem executing plink(putty) command - putty

I am using Plink to execute remote command:
When using this from cmd prompt in single line it doesnot work:
C:\>c:\plink.exe -l userId -pw psw -m C:\goto\test.bat remote_host
It says unable to open command file "C:\goto\test.bat"
But The following works:
C:\>c:\plink.exe -l userId -pw psw remote_host
C:\>C:\goto\test.bat
Please help.

Try running it like this:
c:\plink.exe -l userId -pw psw remote_host C:\goto\test.bat

Judging by some documentation, this should work:
C:\>c:\plink.exe -l userId -pw psw remote_host C:\goto\test.bat

This has worked for me:
Call \\LocalServerName\plink.exe -pw PASSWORD -m D:\FOLDER\FILE.exe USER#REMOTESERVER
Or if its a local computer:
Call c:\Folder\plink.exe -pw PASSWORD -m D:\FOLDER\FILE.exe USER#REMOTESERVER
Caps - Change it to your state

Related

ssh batch script windows : unable to send my commands

I wrote a little script, to automate some actions on a server
#echo off
SET /P host= enter host adress :
#echo off
plink.exe -ssh user#%host% -P 22 -pw password -batch -m "C:\path\to\my_commands.txt"
pause
I can connect with this script, no problem with that. But when I run it, it's not sending what I wrote in my_commands.txt
I've tried to wrote my commands like this :
plink.exe -ssh user#%host% -P 22 -pw password -batch mkdir /my/path
I've tried with or without quotes for the path to my_commands.txt
In both ways, cmd keep telling "bash : mkdir : command not found"
It look like cmd is trying to take the "my_commands.txt" as parameter.

Send multiple commands with Plink and SSH

I'm using a batch file which contains the following information:
plink.exe -ssh loginuser#192.168.0.1 -pw intec -m t.txt
m.txt contains user and password example:
su
intec
Result:
C:\Plink>plink.exe -ssh loginuser#192.168.0.1 -pw intec -m t.txt
Password:_
The problem is that the cursor is waiting for the password.
How do I send the password to pass this step?
If you want to pass the password, I believe it needs to use the -pw option followed by the actual password, not a filename.

Automatic login using PUTTY.EXE with Sudo command

I am using below command to open putty through windows command prompt:
PUTTY.EXE -ssh -pw "mypass" user#IP -m C:/my.sh -t
Where my.sh mentioned in above command file contains:
sudo su - rootuser
After executing the command, putty console is opened and it prompts for password.
Is there any way where I can provide this password automatically without typing it?
There's a bit of a horrible workaround using Expect and embedding a password.
This is a bad idea.
As an alternative:
Configure sudo to allow NOPASSWD.
Login directly as root using public-private key auth.
Both these introduce a degree of vulnerability, so should be used with caution - but any passwordless auth has this flaw.
Finally, after struggling for almost whole day, I got the way to get this working.
Below command can be executed from windows machine:
PLINK.EXE -t -ssh -pw "password" user#IP /home/mydir/master.sh
master.sh file is located on remote machine. And this file contains below command to execute script with sudo command without prompting password.
echo password | sudo u user -S script.sh
Here, password should be replaced with your password. user should be replaced with your actual user and script.sh is the script on remote machine that you want to fire after sudo login.

No password for psExec works, but empty string to password flag does not

I'm using a program called psExec to remotely connect to a machine and start an interactive program.
The machine I'm connecting to, does not have a password.
So if I run this:
psExec \\Computer_Name -u User -i -d calc.exe
It prompts me for a password:
Password:
I just hit enter(since the computer doesn't have a password), and it works.
I don't want to have to hit enter every time, because I am writing a script.
So I tried this:
psExec \\Computer_Name -u User -p -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p"" -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p'' -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p "" -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p '' -i -d calc.exe
but no matter what, specifying the p flag results in a "Wrong Username or Password error."
How can I tell my script to either press enter automatically, or automate psExec to connect automatically without a password?
I'm in PowerShell if that is relevant.
PSEXEC is a program that is offered as a suite of tools from Microsoft. PSEXEC Link
but for security reasons this can cause some issues, you can add a second account to the machine and give it a simple password and run the script against that account, that would be the easiest way, other wise you can most likely accomplish the same task in powershell not using PSEXEC, what is it that you are trying to do and we can try help get something written.
UPDATE:
param (
[Parameter(Mandatory = $true)]
$Password
)
psExec \\OAIJCTDU8024272 -u User -p $Password -i -d calc.exe
It seems to work if you put a ~ for the password in powershell.
./psexec -i -u domain\gmsa$ -p ~ notepad.exe
My use case was getting it to skip the enter keypress when using psexec to run something as a group managed service account (gMSA).
Give this a shot when all else fails. It just passes a return.
Write-Host "" | psExec \\Computer_Name -u User -i -d calc.exe

Batch script to log in SSH server on Windows

I'm trying to make a batch script to log in into a SSH server and execute a few commands. The start command is:
plink -ssh user#99.99.999.99
Then I need to enter the User Name and Password like the image:
If I have the 'User Name' and 'Password' in two variables, how do I use them when it asks me for?
[EDIT]
last try was this:
(echo username
echo mypassword) | plink -ssh user#99.99.999.99
Output:
User Name:username
mypassword
Password:
The batch didn't "pressed" enter after inputing the username.
Try
plink -ssh -l $USER -pw $PASSWD
after setting environment variables
set USER=name
set PASSWD=secret
see http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html

Resources