Execute ssh with password authentication via windows command prompt

后端 未结 5 928
走了就别回头了
走了就别回头了 2020-12-07 13:02

I need to execute ssh from windows command line by providing password in a non interactive manner. I could implement the key based authenti

相关标签:
5条回答
  • 2020-12-07 13:22

    What about this expect script?

    #!/usr/bin/expect -f
    spawn ssh root@myhost
    expect -exact "root@myhost's password: "
    send -- "mypassword\r"
    interact
    
    0 讨论(0)
  • 2020-12-07 13:27

    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.

    0 讨论(0)
  • 2020-12-07 13:30

    Windows Solution

    1. Install PuTTY
    2. Press Windows-Key + R
    3. Enter putty.exe -ssh [username]@[hostname] -pw [password]
    0 讨论(0)
  • 2020-12-07 13:38

    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.

    0 讨论(0)
  • 2020-12-07 13:40

    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
    
    0 讨论(0)
提交回复
热议问题