Google Cloud: Compute VM Instances

2019-02-01 23:45发布

问题:

How do I get root access to my Google VM instance, and also how can I log into my VM Instance from my PC with a SSH client such as putty?

I would also like to add that I have tried to do sudo for things that need root access to do those things, such as yum or wget. But it does not allow me to do sudo, it asks me for the root password but I do not know how, or where I would be able to get the root password.

回答1:

You can become root via sudo su. No password is required.



回答2:

How do I use sudo to execute commands as root?

(splitting this off from the other answer since there are multiple questions within this post)

Once you connect to your GCE VM using PuTTY or gcloud compute instances ssh or even clicking on the "SSH" button on the Developers Console next to the instance, you should be able to use the sudo command. Note that you shouldn't be using the su command to become root, just run:

sudo [command]

and it should not prompt you for a password.

If you want to get a root shell to run several commands as root and you want to avoid prefixing all commands with sudo, run:

sudo su -

If you're still having issues, please post a new question with the exact command you're running and the output that you see.



回答3:

if you want to connect your gce (google-cloud) server with putty using root, here is the flow:

use puttygen to generate two ppk files:

  1. for your gce-default-user

  2. for root

do the followings on putty (replace gce-default-user with your gce username):

Putty->session->Connection->data->Auto-login username: gce-default-user

Putty->session->Connection->SSH->Auth->Private-key for authentication: gce-default-user.ppk

Then connect to server using your gce-default-user

make the following changes in sshd_config

sudo su

nano /etc/ssh/sshd_config

PermitRootLogin yes

UsePAM no

Save+exit

service sshd restart

Putty->session->Connection->data->Auto-login username: root

Putty->session->Connection->SSH->Auth->Private-key for authentication: root-gce.ppk

Now ou can login to root via putty.

If you need to use eclipse remote system and log-in as root:

Eclipse->windows->preferences->General->network Connection->SSH2->private-keys: root-gce.ppk



回答4:

sudo su root <enter key>

No password required :)



回答5:

Please try sudo su - on GCE.
By default on GCE, there is no password required to sudo (do as a substitute user). The - argument to su (substitute user) further simulates a full login, taking the target user (the default user for both is root) configured login shell and its profile scripts to set new environment parameters. You'll at least notice the prompt change from ending in $ to # in any case.



回答6:

JUST GOT TO CLOUD SHELL BY CLICKING SSH

AND FOLLOW PASSWORD CHANGE COMMAND FOR ROOT USER USING SUDO :)

sudo passwd

and it will change the root password :)

then to becom root use command

su

type your password and become a root :)



回答7:

How do I connect to my GCE instance using PuTTY?

(splitting this off from the other answer since there are multiple questions within this post)

Take a look at setting up ssh keys in the GCE documentation which shows how to do it; here's the summary but read the doc for additional notes:

  1. Generate your keys using ssh-keygen or PuTTYgen for Windows, if you haven't already.
  2. Copy the contents of your public key. If you just generated this key, it can probably be found in a file named id_rsa.pub.
  3. Log in to the Developers Console.
  4. In the navigation, Compute->Compute Engine->Metadata.
  5. Click the SSH Keys tab.
  6. Click the Edit button.
  7. In the empty input box at the bottom of the list, enter the corresponding public key, in the following format:

    <protocol> <public-key> username@example.com

    This makes your public key automatically available to all of your instances in that project. To add multiple keys, list each key on a new line.
  8. Click Done to save your changes.

    It can take several minutes before the key is inserted into the instance. Try connecting with ssh to your instance. If it is successful, your key has been propagated to the instance.