简体   繁体   English

在Google Cloud Platform上为其他帐户创建SSH密钥

[英]Create an SSH key for other account on Google Cloud Platform

I have installed the Cloud SDK for Google Cloud. 我已经安装了适用于Google Cloud的Cloud SDK。 I've logged in using auth which redirected me to the gmail-login. 我已经使用auth登录,将我重定向到gmail-login。 Created the SSH key and even logged in by SFTP using Filezilla. 创建了SSH密钥,甚至使用Filezilla通过SFTP登录。

The problem is, when I log in using the gmail auth, SDK shell (or putty?) logs me into an account that is not admin. 问题是,当我使用gmail身份验证登录时,SDK Shell(或腻子?)将我登录到不是admin的帐户中。 It has created another SSH user account (named 'Acer', after my pc) and logs me into it. 它已经创建了另一个SSH用户帐户(在我的PC后命名为“ Acer”),并将我登录到该帐户。 Due to this, FTP starts at the /home/Acer folder. 因此,FTP从/home/Acer文件夹启动。 I want access to the /home/admin/web folder, but I don't have it now. 我想访问/home/admin/web文件夹,但是现在没有。

How can I create a SSH key for the admin account so that I can gain access to the folder mentioned above? 如何为管理员帐户创建SSH密钥,以便可以访问上述文件夹? Otherwise, is it possible to grant 'Acer' the permissions to access all the folders? 否则,是否可以授予“ Acer”访问所有文件夹的权限?

I have a few suggestions. 我有一些建议。

First a bit of background. 首先介绍一下背景。 If you run this command on your home workstation: 如果您在家庭工作站上运行此命令:

sudo find / -iname gcloud

You'll discover a gcloud configuration folder for each user on your home workstation. 您将在家庭工作站上为每个用户发现一个gcloud配置文件夹。 You'll probably see something like this: 您可能会看到以下内容:

/root/.config/gcloud
/home/Acer/.config/gcloud

If you change directory into /home/Acer/.config/gcloud/configurations you'll see a file named 'config_default'. 如果将目录更改为/home/Acer/.config/gcloud/configurations您将看到一个名为“ /home/Acer/.config/gcloud/configurations的文件。 This file will contain the default account to use for that user ('Acer'). 该文件将包含用于该用户的默认帐户(“ Acer”)。

Because you have performed gcloud auth login as that user, and during that process selected your gmail account, it will contain that gmail ID/account within the config file for that user. 由于您已以该用户gcloud auth login执行gcloud auth login ,并且在该过程中选择了您的gmail帐户,因此它将在该用户的配置文件中包含该gmail ID /帐户。 If you would like a user named 'admin' to log into your project, you could try adding a user named 'admin' to your home workstation, and then before attempting to use gcloud auth login , ensure you switch user on your home workstation to user 'admin'. 如果您希望名为“ admin”的用户登录到您的项目,则可以尝试将名为“ admin”的用户添加到您的家庭工作站,然后再尝试使用gcloud auth login ,确保将家庭工作站上的用户切换为用户“ admin”。 This will generate a gcloud configuration on your home workstation for user admin, and propagate SSH keys etc. 这将在家庭工作站上为用户admin生成gcloud配置,并传播SSH密钥等。

If you want to create ssh keys manually there's some useful info here . 如果要手动创建ssh密钥,请在此处找到一些有用的信息。

(For what it's worth, if you decide to use gcloud compute ssh to log into your instance home workstation, you can specify the user in the command you would like to log in as. For example gcloud compute ssh admin@INSTANCE_NAME ). (为此,如果决定使用gcloud compute ssh登录实例家庭工作站,则可以在您要登录的命令中指定用户。例如, gcloud compute ssh admin@INSTANCE_NAME )。

I want access to the /home/admin/web folder, but I don't have it now. 我想访问/ home / admin / web文件夹,但是现在没有。

Even if you are logged into the machine as a different user (in this case 'Acer'), the folder /home/admin/web should still exist on the instance if it existed previously. 即使您以其他用户身份登录计算机(在本例中为“ Acer”),如果以前存在,文件夹/home/admin/web仍应存在于实例上。 If you land in folder /home/Acer have you tried changing directory to the folder above and then listing the folders to see if /home/admin/ exists? 如果您进入/home/Acer文件夹,是否尝试过将目录更改为上面的文件夹,然后列出这些文件夹以查看/home/admin/存在?

For example, from /home/Acer run: 例如,从/home/Acer运行:

$ cd ..

then 然后

$ ls

You should be able to see /home/admin/ . 您应该能够看到/home/admin/

Otherwise, is it possible to grant 'Acer' the permissions to access all the folders? 否则,是否可以授予“ Acer”访问所有文件夹的权限?

Yes this is also possible. 是的,这也是可能的。 If you access the instance as the project owner (the easiest way would be to log into the Console as the owner of the project and use the SSH functionality in the console to access the instance). 如果您以项目所有者的身份访问实例(最简单的方法是以项目所有者的身份登录控制台,并在控制台中使用SSH功能访问实例)。 Now you can run this command: 现在,您可以运行以下命令:

$ sudo chown Acer.Acer -R /home/admin/web

This will make user 'Acer' owner of directory /home/admin/web and all files/directories below it (thanks to the -R switch). 这将使用户'Acer'拥有目录/home/admin/web及其下面的所有文件/目录(由于-R开关)。

Now when you next access the instance as user 'Acer' you'll be able to access /home/admin/web by running the following and you'll also have read/write capabilities: 现在,当您下次以“ Acer”用户身份访问实例时,您将可以通过运行以下命令来访问/home/admin/web ,并且还具有读/写功能:

$ cd /home/admin/web 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM