引言
学校里要编辑台式机上的文件,准备用VSCode Remote来做,但是做了才发现貌似默认情况下Windows是不配备ssh服务器的。
解决方案
启用ssh服务器功能
- Windows 10 设置中管理可选功能
 
- 选择添加功能
开机自动启动方案
因为在powershell中, 开启服务命令为:
start-service sshd我们不妨写一个脚本:
#region 关键代码:强迫以管理员权限运行
$currentWi = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentWp = [Security.Principal.WindowsPrincipal]$currentWi
if( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
  $boundPara = ($MyInvocation.BoundParameters.Keys | foreach{
     '-{0} {1}' -f  $_ ,$MyInvocation.BoundParameters[$_]} ) -join ' '
  $currentFile = (Resolve-Path  $MyInvocation.InvocationName).Path
 $fullPara = $boundPara + ' ' + $args -join ' '
 Start-Process "$psHome\powershell.exe"   -ArgumentList "$currentFile $fullPara"   -verb runas
 return
}
#endregion
Start-Service sshd
echo "SSH Service Status: "
Get-Service sshd
pause扔进启动文件夹即可, 或者创建快捷方式:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <脚本文件位置>
