使用 powershell 将 Linux shell 脚本文件从 windows 插入到 Linux 框

inserting the Linux shell script file from windows to Linux box using powershell

所以我正在使用 power shell 并在 C 驱动器中创建了 shell 脚本文件,现在我想使用 power shell 使用 plink.exe 发送该文件到 Linux 框。 尝试了以下命令

PS C:\> .\plink.exe -pw  -i "R***t" root@192.168.1.12 ".\adduser.sh"
Unable to open connection:

PS C:\> .\plink.exe -i ssh "R***t" root@192.168.1.12 ".\adduser.sh"

PS C:\> .\plink.exe -i ssh "R***t" -P 22 root@192.168.1.12 ".\adduser.sh"
Unable to open connection:

PS C:\> .\plink.exe -i ssh "R***t" -P 22 root@192.168.1.12 ".\adduser.sh"
Unable to open connection:

基本上我们如何使用 g plink.exe 通过电源 shell

连接到 Linux 盒子

if we need any sshkey let me confirm and how can we generate the ssh key for plink.exe and what are the options need to use for ssh key

所以,如果有任何宝贵的建议,请提前致谢......

plink 只是 putty 的一个 command-line 接口。类似于unix/linux中的ssh命令。您不能使用 plink upload/transfer 文件。

您可以使用 pscp 来完成。

这里是关于如何创建 SSH 密钥以在不使用密码的情况下连接到服务器的参考。

https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter8.html#pubkey

plink 是 Simon Tatham 的 SSH 软件包 PuTTY 的整个套件中的一个工具。 PuTTY 为 WIndows 用户提供 SSH 功能,并且它附带了一堆已编译的命令行工具。

Plink 相当于 linux 机器上的 SSH(安全(远程)shell)命令。 Pscp 相当于 SCP (Secure CoPy) 命令。 Psftp 等同于 SFTP(安全文件传输协议),它使用与 SCP 相同的传输方法,但具有类似于 FTP 的命令行界面。 PuTTY 本身是一个图形工具,它使用与 plink 相同的代码来创建远程 shells 或通过 SSH 或 Telnet 协议(以及更多)的命令,但现在可能有点多。

从表面上看,您似乎正在尝试将 shell 脚本复制到您的 Linux 服务器,因此您不应该使用命令打开 shell,而是使用命令进行安全复制。

简而言之,使用 PSCP,而不是 PLINK。 (也许阅读它的手册,所以你得到正确的参数)

我已经简单地尝试了 "Post-SSH" third-party 模块到 Powershell,它看起来相当不错。 :) Find-module Posh-SSH

Find-module Posh-SSH | Install-module

之后你可以

$session = New-SSHSession -ComputerName "1.2.3.4" -Credential (Get-Credential) Invoke-SSHCommand -Session $session -Command 'ls -l'

最后再次关闭会话

$session | Remove-SSHSession

http://www.thomasmaurer.ch/2016/04/using-ssh-with-powershell/

要将 shell 脚本文件从 windows 机器插入到 Linux 框,您需要从互联网下载 "plink" 文件并将其保存在 C:\drive和 运行 下面的命令

PS C:\> .\pscp.exe .\abc.sh root@1.2.3.4.:/root

之后,您可以通过以下命令使用 plink 连接 linux 框

PS C:\> .\plink.exe -pw "L****e" root@1.2.3.4 -P 22 "ls"

here "-pw" means password and "-P" means port number