Reset Linux User Password on Google Cloud Computer

if your root password is fotget,You can reset it using the following method .

Description

Environment

  1. GCP security group allows 0.0.0.0/0 to access the SSH port;
  2. In the operating system, Firewall-cmd specifies the IP that can access the SSH port
  3. In the operating system, /etc/hosts.deny and /etc/hosts.allow are set
  4. Disable root user login

Failure

For some reason, all user passwords are lost and need to be reset.

Solution

  1. you need to shut down(Stop) the server.

gcp-reset-linux-user-password-stop.png

  1. click EDIT image.png

  2. Copy the following code to the Startup script. image.png

#!/usr/bin/bash
echo  'USER:NEW-PASSWORD' | chpasswd # Pls replace USER:NEW-PASSWORD with the username and new password you want to reset.
mv /etc/hosts.allow /etc/hosts.allow.bak
mv /etc/hosts.deny /etc/hosts.deny.bak
systemctl disable firewalld
sed -i "s/PermitRootLogin no/PermitRootLogin yes/g" /etc/ssh/sshd_config
  1. Then, save and start the server, and you can log in to the server using the new password.