【问题标题】:Enter-PSSession Centos To WindowsEnter-PSSession Centos To Windows
【发布时间】:2019-01-09 03:31:38
【问题描述】:

在 Centos 7 上使用 PowerShell 版本 6.0.2,尝试获取到 Windows 2012 Server 的会话。 执行以下操作:

$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force

$mycreds = New-Object System.Management.Automation.PSCredential ("domain\username", $secpasswd)

Enter-PSSession -ComputerName Some-Host-Name -port 5985 -Credential $mycreds

得到以下错误:

 Enter-PSSession : MI_RESULT_ACCESS_DENIED                                                                                       At line:1 char:2
+  Enter-PSSession -ComputerName Some-Host-Name -port 5985 -Credential $m ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Some-Host-Name :String) [Enter-PSSession], PSInvalidOperationException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed

应该获得与 Windows 机器的会话。

为了使 Windows 机器信任 centos 机器,请执行以下操作

Set-Item WSMAN:\Localhost\Client\TrustedHosts -Value * -Force

任何想法我需要做什么?

【问题讨论】:

  • 您的 CentOS 主机是否在 TrustedHosts 列表中有 Windows 主机?否则它们需要在同一个域中,使用 Kerberos 进行身份验证/授权。
  • @TheIncorrigible1 是的。完成以下命令:Set-Item WSMAN:\Localhost\Client\TrustedHosts -Value * -Force
  • 你在两端都这样做了吗?
  • @TheIncorrigible1 1. 为什么centos尝试连接时需要将windows机器加入信任列表? 2. 我该怎么做?
  • 因为它是客户端配置,而不是服务器配置。在这种情况下,您的 CentOS 是一个客户端。您可以像在 Windows 机器上一样完成它。

标签: powershell remote-access powershell-remoting winrm


【解决方案1】:

您需要使用 SSH 从 Linux 远程访问 Windows。 MS 文档网站对此进行了介绍。

通过 SSH 进行 PowerShell 远程处理

概览

PowerShell 远程处理通常使用 WinRM 进行连接协商和 数据传输。 SSH 被选为这个远程实现,因为 它现在可用于 Linux 和 Windows 平台,并允许 真正的多平台 PowerShell 远程处理。但是,WinRM 还提供了一个 强大的 PowerShell 远程会话托管模型,这 实施还没有做。这意味着 PowerShell 远程 端点配置和 JEA(Just Enough Administration)还没有 在此实现中支持。

https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core?view=powershell-6

在 Windows、Mac 和 Linux 上开始使用 PowerShell Core 什么 我需要吗?

要开始使用 PowerShell Core,您需要安装和配置 您选择的操作系统上的这三个项目: • PowerShell Core 6 Beta • OpenSSH • Visual Studio Code

我很惊讶我在遵循 安装说明。每个过程涉及的相对较少 调整以获得测试版体验。

如果您是 Linux 用户,您可能会想:“好吧。我已经有了 已安装 OpenSSH。”请阅读上面的 OpenSSH 链接了解步骤 编辑 sshd_config 文件以支持 PowerShell 远程处理。

https://blogs.msdn.microsoft.com/powershell/2017/06/09/getting-started-with-powershell-core-on-windows-mac-and-linux

或者也可以看看这些答案:

从 Linux 终端管理 Windows Powershell

https://serverfault.com/questions/638659/managing-windows-powershell-from-linux-terminal

如何设置 Linux 以查询 Windows WinRM 主机

http://www.tomsitpro.com/articles/setup-linux-to-query-windows-winrm-hosts,1-3468.html

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 2022-12-31
    • 2020-04-03
    • 2017-10-23
    • 1970-01-01
    相关资源
    最近更新 更多