如何在 GCP 中获得对 AI Platform 笔记本的根访问权限?

问题描述

我在 GCP AI Platform 笔记本实例的终端中以用户 jupyter 登录

我只想安装一些东西(无法通过 pip 安装),但我无法以 root 用户身份使用 gcloud 命令进行 ssh。

如果有人能分享一个正确的方法来获得执行这些操作的权限,那就太好了。

这是导致问题的示例包安装的片段-

(base)~/datascience$ sudo cp ./pip-bash-completion/pip /etc/bash_completion.d/

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for jupyter: 

根据我看到的信息,我应该拥有 sudo 访问权限 -

Zone - us-central1-b
Environment  - Python 3 (with Intel® MKL)
Machine type - n1-standard-4 (4 vcpus,15 GB RAM)
GPU - None
Boot disk - 100 GB disk
Data disk - 100 GB disk
Backup - Not specified
Permission mode - Service account
Sudo access - Enabled

解决方法

如果您在 Jupyter 终端中,则应使用 sudo。 一些 IT 管理员通过使用 notebook-disable-root=true 元数据来限制 root 访问。您可以通过访问 Cloud Console 中的笔记本页面来验证这一点。

在禁用 root 的情况下创建新实例的示例:

gcloud notebooks instances create $INSTANCE_NAME \
  --vm-image-project=deeplearning-platform-release \
  --vm-image-family=tf-latest-gpu \
  --metadata="notebook-disable-root=true,proxy-mode=mail,[email protected]" \
  --location=us-west1-a

Google Cloud AI Platform Notebooks 通过 OSLogin 支持 SSH。 https://cloud.google.com/compute/docs/oslogin/manage-oslogin-in-an-org 您需要使用您的 IAM 帐户通过 SSH 连接,然后执行 sudo。