日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

使用 Powershell 远程连接 windows server

發(fā)布時(shí)間:2023/12/4 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用 Powershell 远程连接 windows server 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


使用 Powershell 遠(yuǎn)程連接 windows server

Intro

最近我們的開(kāi)發(fā)環(huán)境增加了一個(gè) windows 服務(wù)器,沒(méi)有界面的,不能直接遠(yuǎn)程桌面連上去管理,需要使用 Powershell 管理,于是就有了這篇文章的探索。

windows服務(wù)器配置

以下所有命令需要在管理員賬戶下執(zhí)行,請(qǐng)以管理員身份運(yùn)行下面的命令。

  • 在遠(yuǎn)程 windows服務(wù)器上啟用 powershell 遠(yuǎn)程會(huì)話:

  • Enable-PSRemoting -Force

  • 配置 TrustedHosts

  • winrm set winrm/config/client '@{TrustedHosts="<your local ip>"}'

  • # winrm set winrm/config/client '@{TrustedHosts="58.123.45.26,134.86.23.21"}' #多個(gè)地址用英文的逗號(hào)分隔

  • 配置好之后需要重啟一下服務(wù):

  • Restart-Service WinRM

  • 防火墻開(kāi)放 5985 端口

  • winrm 有兩個(gè)端口號(hào),你可以用 winrmgetwinrm/config/client 命令來(lái)查看 winrm client 相關(guān)配置信息,

    可以看到默認(rèn)的兩個(gè)端口

    • http:5985

    • https:5986

    我們只用了 http 所以開(kāi)放 5985 端口

    本地配置

  • 配置 TrustedHosts

  • winrm set winrm/config/client '@{TrustedHosts="<remote server ip or host>"}'

  • # winrm set winrm/config/client '@{TrustedHosts="58.123.45.26,134.86.23.21"}' #多個(gè)地址用英文的逗號(hào)分隔

  • 連接遠(yuǎn)程服務(wù)器

  • Enter-PSSession -ComputerName <remoteIp or host> -Credential <username>

  • 連接之后,會(huì)提示輸入對(duì)應(yīng)用戶的密碼,提交之后就會(huì)進(jìn)行身份驗(yàn)證

    出現(xiàn)如下圖所示的提示就說(shuō)明連接成功了,在執(zhí)行命令就相當(dāng)于是在遠(yuǎn)程windows服務(wù)器上執(zhí)行命令了,就相當(dāng)于是 SSH 到了 linux 服務(wù)器上了

    疑難解答

  • ACCESS IS DENIED

  • 如果你的用戶名密碼都是正確的,但是還是一直提示 ACCESS IS DENIED,那么你需要檢查一下這個(gè)用戶是否有 Remote 的權(quán)限,遠(yuǎn)程的用戶至少要有 Remote 的權(quán)限,把用戶加入到 RemoteDesktopUsers 這個(gè)用戶組中就會(huì)有Remote 的權(quán)限

    更多問(wèn)題請(qǐng)參考: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/aboutremotetroubleshooting?view=powershell-6

    Reference

    • https://www.faqforge.com/windows/create-powershell-session-remote-computer/

    • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/aboutremotetroubleshooting?view=powershell-6

    • https://docs.microsoft.com/en-us/windows-server/administration/server-manager/server-manager

    • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/enter-pssession?view=powershell-6

    • https://www.itprotoday.com/windows-78/how-remotely-manage-windows-server-2016


    創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

    總結(jié)

    以上是生活随笔為你收集整理的使用 Powershell 远程连接 windows server的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。