Is there any solution to gain access of the password of user account in VM instance in Google Cloud Platform
I'm using the VM compute engine service Of GCP, in which I have created a instance of Ubuntu-pro but when I go to terminal for like sudo command it ask me the password every time for the user account but my question is that I have not set any password yet but its asking again and again. So how I can know the password of user account in ubuntu vm instance
3 answers
-
answered 2022-01-19 17:34
Leo
If you don't have the root password for your vm, you could use a startup script to add it to your instance, the script would be like this:
Go to the VM instances page in Google Cloud Platform console.
Click on the instance for which you want to add a startup script.
Click the Edit button at the top of the page.
Click on ‘Enable connecting to serial ports.
Under Custom metadata, click Add item.
Set 'Key' to 'startup-script' and set 'Value' to this script:
#! /bin/bash useradd -G USERNAME echo USERNAME:PASSWORD | chpasswd
Click Save and then click RESET on the top of the page.
You might need to wait for some time for the instance to reboot. Click on 'Connect to serial port' in the page. In the new window, you might need to wait a bit and press on Enter of your keyboard once; then, you should see the login prompt. Login using the USERNAME and PASSWORD you provided. In this way you can login at the vm and stop the firewall service to modify your rules before to start the service again. So in order to enable OS login you can setting metadata values at the instance or project level. but you need proceed with caution because enabling OS Login on instances disables metadata-based SSH key configurations on those instances. You can find more information related in this link
-
answered 2022-01-19 20:44
PeteP
Linux accounts in GCP use SSH keys instead of passwords, so you don't have a password by default.
Your user account isn't in thegoogle-sudoers
group, which is insudoers
withNOPASSWD:ALL
set.
It's possible that the VM hasn't finished running the startup script for some reason, I saw that enough times to write a wiki page at a previous job. Check the serial port 1 log for errors, especiallygoogle-startup-scripts.service
.
It's also possible that your Google account doesn't have theroles/compute.osAdminLogin
permission, which would explain why you aren't allowed to sudo without a password. If that's the case then you can add this to the startup script to force adding it:useradd -G google-sudoers account_name
Though getting the
roles/compute.osAdminLogin
permission would give you access without rebooting the VM. -
answered 2022-01-20 04:15
Scott Summers
There are no password on GCP linux VM by default, you will need to manually set it up. To do that, follow the steps below:
- Open SSH Connection to VM.
- Type
sudo su
(to switch to root user) - Type
sudo passwd
(to create password for root user) The result should look like this:
New password: Retype new password: passwd: password updated successfully
- Type
whoami
(to verify the user)
do you know?
how many words do you know