簡體   English   中英

如何將 scp 和 ssh 安裝到 Powershell?

[英]How to install scp and ssh to Powershell?

我使用以下命令安裝了 Posh-SSH:Install-Module -Name Posh-SSH

嘗試執行 scp 或 ssh 時,我得到如下內容。 為什么?

scp : The term 'scp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ scp
+ ~~~
    + CategoryInfo          : ObjectNotFound: (scp:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

更新在@tommymaynard 的幫助下,我可以看到所有可用的命令:

PS C:\WINDOWS\system32> $x = Find-Module -Name Posh-SSH
PS C:\WINDOWS\system32> $x.AdditionalMetadata.Functions -split ' '
Get-PoshSSHModVersion
Get-SFTPChildItem
Get-SFTPContent
Get-SFTPLocation
Get-SFTPPathAttribute
Get-SFTPSession
Get-SSHPortForward
Get-SSHSession
Get-SSHTrustedHost
Invoke-SSHCommand
Invoke-SSHCommandStream
Invoke-SSHStreamExpectAction
Invoke-SSHStreamExpectSecureAction
Invoke-SSHStreamShellCommand
Move-SFTPItem
New-SFTPFileStream
New-SFTPItem
New-SFTPSymlink
New-SSHDynamicPortForward
New-SSHLocalPortForward
New-SSHRemotePortForward
New-SSHShellStream
New-SSHTrustedHost
Remove-SFTPItem
Remove-SFTPSession
Remove-SSHSession
Remove-SSHTrustedHost
Rename-SFTPFile
Set-SFTPContent
Set-SFTPLocation
Set-SFTPPathAttribute
Start-SSHPortForward
Stop-SSHPortForward
Test-SFTPPath
PS C:\WINDOWS\system32> $x.AdditionalMetadata.Cmdlets -split ' '
Get-SCPFile
Get-SCPFolder
Get-SCPItem
Get-SFTPFile
Get-SFTPItem
New-SFTPSession
New-SSHSession
Set-SCPFile
Set-SCPFolder
Set-SCPItem
Set-SFTPFile
Set-SFTPFolder
Set-SFTPItem

從那里,您將使用哪個命令來替換下面的“scp”和“ssh”(參考: https : //code.visualstudio.com/docs/remote/troubleshooting#_configuring-key-based-authentication )?

$REMOTEHOST="your-user-name-on-host@host-fqdn-or-ip-goes-here"

scp "$env:USERPROFILE\.ssh\id_rsa.pub" "${REMOTEHOST}:~/tmp.pub"
ssh "$REMOTEHOST" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat ~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm -f ~/tmp.pub"

您安裝的模塊不包含名為“scp”的函數/cmdlet。 我沒有安裝模塊,但確實運行了以下命令來確定模塊中函數和 cmdlet 的名稱。

$x = Find-Module -Name Posh-SSH
$x.AdditionalMetadata.Functions -split ' '
$x.AdditionalMetadata.Cmdlets -split ' '

編輯:您是否閱讀了 *scp* 命令的幫助? 我做到了。 其中之一一定會做你需要的。 我繼續在我的計算機上安裝了該模塊並運行以下命令以快速獲取此模塊中 *scp* 命令的概要。

Install-Module -Name Posh-SSH
Get-Command -Module Posh-SSH -Name *scp* |
ForEach-Object {"$($_.Name): $((Get-Help -Name $_).Synopsis)"}

Get-SCPFile: Download a File from a SSH Server using SCP
Get-SCPFolder: Download a folder from a SSH Server using SCP.
Get-SCPItem: Download from a remote server via SCP a file or directory.
Set-SCPFile: Copies a file to a SSH server using SCP.
Set-SCPFolder: Copies a folder to a SSH server using SCP.
Set-SCPItem: Upload an item, either file or directory to a remote system via SCP.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM