我正在努力在遠端伺服器(Windows Server 2022 Standard)上開啟遠端 PS 會話。遠端伺服器是不是域的一部分。
運行命令時
Enter-PSSession -ComputerName server01 -Credential server01\administrator
我收到“訪問被拒絕”。
我做了什麼:
- 伺服器
Enable-PSRemoting
Enable-WSManCredSSP -Role server
- 客戶
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "`n192.168.1.250`tserver01"
winrm quickconfig
Set-Item WSMan:\localhost\Client\TrustedHosts -Value server01
在客戶端執行時
Enter-PSSession -ComputerName server01 -Credential server01\administrator
並輸入我收到的密碼:
Enter-PSSession :在遠端伺服器「server01」上查看以下資訊:Zugriff verweigert Weitere Informationen finden Sie im Hilfethema「about_Remote_Troubleshooting」。在Zeile:1 Zeichen:1 + Enter-PSSession -ComputerName server01 -Credential server01\administrator + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (server01:String) [Enter- PSSession],PSRemotingTransportException + ExcellentQualifiedErrorId:CreateRemoteRunspaceFailed
在客戶端執行時
winrm identify -r:http://server01:5985 -u:server01\Administrator -p:secret
我收到
WSManFault 訊息 = Zugriff verweigert
費勒編號:-2147024891 0x80070005 Zugriff verweigert
我缺什麼?
更新:
在 winrm 配置中,我設定了和Auth/Basic
(客戶端和服務)-相同的結果。我然後AllowUnencrypted
true
配置的 HTTPS 訪問使用自簽名憑證 - 相同的結果。
由於伺服器端沒有條目,Microsoft-Windows-Windows Remote Management/Operational
因此看起來請求在客戶端被封鎖。Test-NetConnection -ComputerName server01 -Port 5985
成功(與連接埠 5986 相同)。
答案1
因為您使用的是非網域用戶,所以我的第一個猜測是這UAC
可能會阻止您。
我想說這個錯誤是由客戶端引發的,所以首先嘗試UAC
在客戶端上停用。如果這不起作用,請UAC
在伺服器上停用。
如果不UAC
相關,我可以想像這個本機管理員帳戶需要是Remote Management Users
伺服器上群組的成員。
至少那是我接下來要嘗試的。
答案2
winrm get winrm/config
您需要包含伺服器上的輸出。透過 HTTP 使用基本驗證透過網路將憑證傳送到未加密的主機,因此該服務通常預設為停用它。
另請檢查 Windows 遠端管理事件日誌 (Microsoft-Windows-Windows 遠端管理/操作)。
winrm get winrm/config
Config
MaxEnvelopeSizekb = 500
MaxTimeoutms = 60000
MaxBatchItems = 32000
MaxProviderRequests = 4294967295
Client
NetworkDelayms = 5000
URLPrefix = wsman
AllowUnencrypted = false
Auth
Basic = true
Digest = true
Kerberos = true
Negotiate = true
Certificate = true
CredSSP = false
DefaultPorts
HTTP = 5985
HTTPS = 5986
TrustedHosts
Service
RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
MaxConcurrentOperations = 4294967295
MaxConcurrentOperationsPerUser = 1500
EnumerationTimeoutms = 240000
MaxConnections = 300
MaxPacketRetrievalTimeSeconds = 120
AllowUnencrypted = false
Auth
Basic = false **
Kerberos = true
Negotiate = true
Certificate = false
CredSSP = false
CbtHardeningLevel = Relaxed
DefaultPorts
HTTP = 5985
HTTPS = 5986
IPv4Filter = *
IPv6Filter = *
EnableCompatibilityHttpListener = false
EnableCompatibilityHttpsListener = false
CertificateThumbprint
AllowRemoteAccess = true
Winrs
AllowRemoteShellAccess = true
IdleTimeout = 7200000
MaxConcurrentUsers = 2147483647
MaxShellRunTime = 2147483647
MaxProcessesPerShell = 2147483647
MaxMemoryPerShellMB = 2147483647
MaxShellsPerUser = 2147483647
答案3
我找到了解決方案。我只需添加-Authentication Basic
到Enter-PSSession
命令中即可。
完整命令:
Enter-PSSession -ComputerName server01 -Authentication Basic -Credential administrator
使用時winrm identify
我必須添加-auth:basic
:
winrm identify -r:http://server01:5985 -a:basic -u:Administrator -p:secret
就是這麼簡單...