Execute ssh with password authentication via windows command prompt

WindowsSshCommand LinePasswords

Windows Problem Overview


I need to execute ssh from windows command line by providing password in a non interactive manner. I could implement the key based authentication and able to execute the ssh commands just like

ssh <user>@<host> <command>

Is there any commands like

ssh <user>@<host> -P <password> <command>

enter image description here

I don't know if it is feasible. However, there can be some work around for the same. Throw me some ideas to accomplish the same.

Windows Solutions


Solution 1 - Windows

The sshpass utility is meant for exactly this. First, install sshpass by typing this command:

sudo apt-get install sshpass

Then prepend your ssh/scp command with

sshpass -p '<password>' <ssh/scp command>

This program is easiest to install when using Linux.

User should consider using SSH's more secure public key authentication (with the ssh command) instead.

Solution 2 - Windows

What about this expect script?

#!/usr/bin/expect -f
spawn ssh root@myhost
expect -exact "root@myhost's password: "
send -- "mypassword\r"
interact

Solution 3 - Windows

PuTTY's plink has a command-line argument for a password. Some other suggestions have been made in the answers to this question: using Expect (which is available for Windows), or writing a launcher in Python with Paramiko.

Solution 4 - Windows

Windows Solution

  1. Install PuTTY
  2. Press Windows-Key + R
  3. Enter putty.exe -ssh [username]@[hostname] -pw [password]

Solution 5 - Windows

PowerShell solution

Using Posh-SSH:

New-SSHSession -ComputerName 0.0.0.0 -Credential $cred | Out-Null
Invoke-SSHCommand -SessionId 1 -Command "nohup sleep 5 >> abs.log &" | Out-Null

Solution 6 - Windows

This post is a valid solution for your issue.

  1. Install PuTTY on your Windows Machine
  2. Execute 'plink your_username@yourhost -pw your_password'

If you use the Windows Terminal and you want your shell to log into a remote machine when opening a new tab, you may configure the command line params (Settings -> Shell -> Command line):

C:\Users\USERNAME\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell.ID\pwsh.exe
-Command "plink [email protected] -pw PASSWORD"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBalachandarView Question on Stackoverflow
Solution 1 - WindowsAnish BhattView Answer on Stackoverflow
Solution 2 - WindowsIllarion KovalchukView Answer on Stackoverflow
Solution 3 - WindowsGreg InozemtsevView Answer on Stackoverflow
Solution 4 - WindowsoptimiertesView Answer on Stackoverflow
Solution 5 - WindowsOwain EsauView Answer on Stackoverflow
Solution 6 - WindowsBin4ryView Answer on Stackoverflow