我需要执行 嘘从 窗口命令行通过提供密码在一个非交互式的方式。我可以实现基于密钥的身份验证,并能够执行 ssh 命令,就像
ssh <user>@<host> <command>
有没有像
ssh <user>@<host> -P <password> <command>
我不知道这是否可行。但是,也可以为同样的事情做一些工作。给我一些想法来实现同样的目标。
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.
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.
ssh
What about this expect script?
#!/usr/bin/expect -f spawn ssh root@myhost expect -exact "root@myhost's password: " send -- "mypassword\r" interact
Windows Solution
Windows-Key + R
putty.exe -ssh [username]@[hostname] -pw [password]
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
This post is a valid solution for your issue.
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 USERNAME@192.168.0.1 -pw PASSWORD"