Amila Kalansooriya
3 min readFeb 4, 2019

--

Resetting the ‘root’ password of your VM on Digital Ocean

Sometime back I had a digital ocean instance running with Ubuntu 16.04. On which I had disabled the ssh login to the root account as a security measure. For performing day to day tasks, I had created a user account called ‘test’. I enabled public key authentication for ‘test’ so that I can use some ssh client (putty or bitwise ssh client) to log into the server without needing to type the password every time. This user (test) is also added to sudoers list so I can perform admin tasks right from the ‘test’ account by typing ‘sudo command …’.

After the initial setup I didn’t login to the server for a while. When I wanted to login at some point though, I have forgotten what was my password for the ‘test’ user. I didn’t even stored the passwords in a password manager like KeePass so I knew I was in trouble. I could still login to the server with ‘test’ user account via SSH (since I have enabled public key authentication), but I was still gonna need to know its password when I tried to execute a command with sudo. So the problem was how can I reset it to a new one? To reset the password I must log into the server as the ‘root’ user.

I knew I couldn’t login as ‘root’ user over SSH as it was disabled for security. Then the only way was to log into the server as ‘test’, then switch to the ‘root’ using ‘su’ command. That could allow me to reset the ‘test’ user’s password.

$ su

When I tried, there came another shocker. It prompted me for the root user password. I couldn’t even remember that as well. So I was stuck. How could I reset the root password? I wasn’t totally out of luck though. I knew Digital Ocean dashboard should give us an option to reset the root password of our server instance. I logged into the digital ocean dashboard and just as I assumed thanks god, I could find the password reset option in its ‘Access’ tab as shown in the below screenshot:

With that option I was able to receive a new temporary root password to my inbox. (to the email address your digital ocean account is registered to). I returned back to my ssh console and attempted to log in as the root user by pasting the temporary password I got from Digital ocean. It logged me in as root user and immediately asked me to change it. So I had to type the temporary password once more. It then asked me to enter a new password and repeat it for verification. After going through those two steps I was able to successfully log in as root. Then I could reset the password for the ‘test’ user. To do that I typed below command:

# passwd username

Note that ‘username’ is the user that you want to reset the password of. In my case it was ‘test’. When prompted, I had to type the new password and repeat it once more for verification.

# Enter new UNIX password:# Retype new UNIX password:

Finally it showed me the message ‘passwd: password updated successfully’.

This is the same process you also have to follow if you got stuck in a similar situation like me ;)

--

--

Amila Kalansooriya

Thinker, Scholar, Teacher, problem solver, and a self-made web developer