To get a root password for the Google Cloud Engine VM, log in to your Virtual Machine using SSH and execute the sudo passwd command. If everything is correct, you will get this output:
user@server[~]# sudo passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Google Cloud Engine (GCE) virtual machines (VMs) do not have a root password by default. Instead, GCE VM instances use SSH keys for authentication. To access the VM as a root user or with root privileges.
Step 1: Connect to the VM via SSH and use ‘sudo’
You can SSH into the VM using the gcloud command-line tool, Google Cloud Console, or an SSH client like PuTTY.
Using the gcloud CLI, run the following command:
gcloud compute ssh your-instance-name --zone your-instance-zone
Replace your-instance-name and your-instance-zone with the appropriate values for your VM.
Step 2: Enable root login (not recommended)
Enabling direct root login is not recommended due to security risks. However, if you still want to enable root login, you can follow these steps:
-
- SSH into your VM using your preferred method (as described earlier).
- Switch to the root user
sudo -i
- Set a root password.
passwd
- Edit the SSH configuration file:
nano /etc/ssh/sshd_config
Find the line that says:
PermitRootLogin prohibit-password
Replace it with:
PermitRootLogin yes
- Restart the SSH service.
sudo service ssh restart
Now, you can log in as the root user with the root password you set. However, this method is not recommended, as it exposes your VM to potential security risks. Using ‘sudo’ is the preferred method for executing commands with root privileges.
That’s it.

Amit Doshi is a Cloud Engineer who has experienced more than 5 years in AWS, Azure, and Google Cloud. He is an IT professional responsible for designing, implementing, managing, and maintaining cloud computing infrastructure, applications, and services.