在 Linux 上设置适用于 PowerShell Core 的 AWS 工具

在 Linux 上设置适用于 PowerShell Core 的 AWS 工具

AWS公用事业关于特权有这样的说法:

笔记

虽然您可以通过运行 sudo pwsh 来以提升的权限运行 PowerShell,但请注意,这是一个潜在的安全风险,并且不符合最小特权原则。

相当合理,但是模块是如何安装的呢?

thufir@dur:~$ 
thufir@dur:~$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/thufir> 
PS /home/thufir> Install-Module -Name AWSPowerShell.NetCore                                                             
Install-Module : Administrator rights are required to install modules in '/usr/local/share/powershell/Modules'. Log on to the computer with an account that has Administrator rights, and then try again, or install '/home/thufir/.local/share/powershell/Modules' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
At line:1 char:1
+ Install-Module -Name AWSPowerShell.NetCore
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
+ FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

PS /home/thufir> 
PS /home/thufir> exit                                                                                                   
thufir@dur:~$ 
thufir@dur:~$ 
thufir@dur:~$ sudo pwsh
[sudo] password for thufir: 
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/thufir> 
PS /home/thufir> Install-Module -Name AWSPowerShell.NetCore                                                             

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its 
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): n
WARNING: User declined to install module (AWSPowerShell.NetCore).
PS /home/thufir> 
PS /home/thufir> exit                                                                                                   
thufir@dur:~$ 

答案1

我相信他们在这里意外交换了命令:

接下来,运行 Install-Module,如以下命令所示。

PS> Install-Module -Name AWSPowerShell.NetCore -AllowClobber

除非您想为计算机的所有用户安装适用于 PowerShell Core 的 AWS 工具,否则无需以管理员身份运行此命令。为此,请在使用 sudo pwsh 启动的 PowerShell 会话中运行以下命令:

PS> Install-Module -Scope CurrentUser -Name AWSPowerShell.NetCore -Force

-Scope CurrentUser仅为您的用户安装此模块,不需要管理员权限。如果没有管理员权限,它将为所有用户安装模块,并且需要权限。请参阅文档Install-Modules

当没有定义作用域,或者参数的值为 时ScopeAllUsers模块安装到。当的 %systemdrive%:\Program Files\WindowsPowerShell\Modules值为 时,模块安装到 。ScopeCurrentUser$home\Documents\WindowsPowerShell\Modules

要不使用 进行安装sudo,请使用。例如,-Scope CurrentUser这类似于。--userpip install

相关内容