Send multiple commands with Plink and SSH - windows

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.

Related

How to pass user input automatically using plink.exe

I need to login to an SSH session using password, and then execute the user input values for a particular account.
For example:
PLINK.EXE -ssh ***** -l ***** -pw *****
I
am able to login, now what I need to do is enter below values:
Please select account to logon: "U"
Press RETURN to continue or OFF to cancel session - "RETURN"
There are similarly this kind of user inputs needed. Is there a way I store the "*" values in a text file and load them using Plink.
I tried:
PLINK.EXE -ssh ***** -l ***** -pw ***** -m C:\input.txt
This does not seems to be working.
Expectation: Passing all the user input i.e. "U", "RETURN" .... using Plink or any other PuTTY tool.
Appreciate your help!
The -m switch is used to execute commands in shell. You cannot use it to provide inputs for the executed commands.
But as Plink is a console application, you can use an input redirection to provide input:
plink.exe -ssh ... -l ... -pw ... < C:\input.txt

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.

Using Plink and redirect output in bash script

I've got problem, I've setup plink to create a connection to a BlueCoat device, retrieve the full configuration and redirect the output to a file.
The problem is, when I try it from the script, the output of plink is displayed on screen and not redirected to the file, but if I use the same exact command interactively, it works!
I've checked the file rights, etc. they all seem to be ok.
The way I use it is:
/usr/bin/plink -4 -batch -ssh -l <user> -pw <password> -m /tmp/bluecoat.backup <hostname> > output.txt
Any clues?
Kind regards,
Chris

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

problem executing plink(putty) command

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

Resources