ssh 进入 windows 10 powershell 并且没有获得管理员权限

gma*_*man 5 ssh powershell windows-10

对于 ssh 我习惯了 unix 系统。我有“sudo”权限,但是当我 ssh 进入我的帐户时,我不是管理员,我只是普通用户。要执行任何管理操作,我必须“sudo”

\n\n

本地也是如此。我打开一个终端,我不是管理员。我只是一个普通用户。

\n\n

即使在 Windows 10 中,如果启动 powershell,我也没有管理员权限。为了获得管理员权限,我必须专门打开并管理 powershell。默认没有管理员权限。

\n\n

我最近在 Windows 10 上使用 powershell 设置了 ssh,但是当我 ssh 进入 shell 时,它说具有管理员权限

\n\n
(New-Object Security.Principal.WindowsPrincipal(\n  [Security.Principal.WindowsIdentity]::GetCurrent())\n).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\nTrue\n
Run Code Online (Sandbox Code Playgroud)\n\n

我怎样才能让它的行为与我在本地启动一个没有管理员权限的 powershell 一样?

\n\n

如果我的桌面上不清楚,我会打开命令提示符并键入pwsh,但我不是管理员

\n\n
Microsoft Windows [Version 10.0.18363.900]\n(c) 2019 Microsoft Corporation. All rights reserved.\n\nC:\\Users\\gregg>pwsh\nPowerShell 7.0.1\nCopyright (c) Microsoft Corporation. All rights reserved.\n\nhttps://aka.ms/powershell\nType \'help\' to get help.\n\nLoading personal and system profiles took 620ms.\n\xe2\x9d\xaf (New-Object Security.Principal.WindowsPrincipal(\n>>   [Security.Principal.WindowsIdentity]::GetCurrent())\n>> ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\nFalse\n
Run Code Online (Sandbox Code Playgroud)\n\n

再次执行此操作,除了 ssh 到本地主机,但不知何故我是管理员

\n\n
Microsoft Windows [Version 10.0.18363.900]\n(c) 2019 Microsoft Corporation. All rights reserved.\n\nC:\\Users\\gregg>ssh localhost\ngregg@localhost\'s password:\nPowerShell 7.0.1\nCopyright (c) Microsoft Corporation. All rights reserved.\n\nhttps://aka.ms/powershell\nType \'help\' to get help.\n\nLoading personal and system profiles took 620ms.\n\xe2\x9d\xaf (New-Object Security.Principal.WindowsPrincipal(\n>>   [Security.Principal.WindowsIdentity]::GetCurrent())\n>> ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\nTrue\n
Run Code Online (Sandbox Code Playgroud)\n\n

这两个命令pwsh应该ssh localhost以相同的情况结束,但事实并非如此。如何修复因此ssh localhost行为与pwsh

\n\n

PS:我发现 powershell 似乎没有“sudo”类型的命令,也没有提升权限的方法。这不是我的问题。我的问题是,当我在本地启动 powershell 时,我不是管理员。当我通过 ssh 启动它时,如何让它表现相同

\n\n

额外问题:如果有一个关于如何以管理员组中的用户身份 ssh 进入 powershell 但在 powershell 中没有管理员权限的答案,那么通过 ssh 选择性启动具有管理员权限的 powershell 的过程是什么?(旗帜等)

\n

Car*_*lsh 3

Windows 在没有管理员权限/提升的情况下启动桌面的方式(即使您的用户帐户位于管理员组中并且应该具有这些权限)是UAC

sshd 服务需要内置一些功能,运行与创建低权限标准访问令牌相同的逻辑,而不是使用默认管理令牌启动 shell 进程。

Windows sshd 文档中,这是我能找到的最相关的语言:

请注意,如果用户属于管理员组,则使用 %programdata%/ssh/administrators_authorized_keys。

所以今天看来该功能不存在。但如果您创建了功能请求,我会+1!


我能想到的其他解决方案是“使用不同的用户”或“运行不同的 ssh 服务器非提升”:(

如果您创建不在管理员组中的其他 Windows 用户帐户并通过 SSH 连接到该用户,您将不会被提升。但这可能没有帮助......

如果您以非提升的方式启动 ssh 服务器,则它生成的 shell 进程也将是非提升的。您可以尝试从 WSL 安装 sshd吗?我没有尝试过,所以我不知道它是否有效。

我还考虑过PowerShell Remoting,但在我的测试中它总是启动一个提升的 shell,与 SSH 相同。