当前位置: 移动技术网 > 科技>操作系统>windows > 使用 Powershell 远程连接 windows server

使用 Powershell 远程连接 windows server

2019年05月29日  | 移动技术网科技  | 我要评论

泡沫之夏漫画结局,龙潭果树公园,南京电视台少儿频道

使用 powershell 远程连接 windows server

intro

最近我们的开发环境增加了一个 windows 服务器,没有界面的,不能直接远程桌面连上去管理,需要使用 powershell 管理,于是就有了这篇文章的探索。

windows服务器配置

以下所有命令需要在管理员账户下执行,请以管理员身份运行下面的命令。

  1. 在远程 windows服务器上启用 powershell 远程会话:
enable-psremoting -force
  1. 配置 trustedhosts
winrm set winrm/config/client '@{trustedhosts="<your local ip>"}'
# winrm set winrm/config/client '@{trustedhosts="58.123.45.26,134.86.23.21"}' #多个地址用英文的逗号分隔

配置好之后需要重启一下服务:

restart-service winrm
  1. 防火墙开放 5985 端口

winrm 有两个端口号,你可以用 winrm get winrm/config/client 命令来查看 winrm client 相关配置信息,

winrm-client-config

可以看到默认的两个端口

  • http: 5985
  • https:5986

我们只用了 http 所以开放 5985 端口

本地配置

  1. 配置 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"}' #多个地址用英文的逗号分隔
  1. 连接远程服务器
enter-pssession -computername <remoteip or host> -credential <username>

连接之后,会提示输入对应用户的密码,提交之后就会进行身份验证

出现如下图所示的提示就说明连接成功了,在执行命令就相当于是在远程windows服务器上执行命令了,就相当于是 ssh 到了 linux 服务器上了

remote ps-session connected

疑难解答

  1. access is denied

如果你的用户名密码都是正确的,但是还是一直提示 access is denied,那么你需要检查一下这个用户是否有 remote 的权限,远程的用户至少要有 remote 的权限,把用户加入到 remote desktop users 这个用户组中就会有remote 的权限

更多问题请参考:

reference

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网