How to reset linux user password?

I have a digital ocean instance running Ubuntu 16.04. On which I have disabled the root account for security purposes. For performing
day to day tasks, I have 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 as ‘test’ 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 …’

Somehow I didn’t login to the server for a while and now I have forgot what 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’ll still gonna need to know its password when I try 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, it prompted me for the root user password. Damn, I couldn’t even remember that as well. So I was stuck. How could I reset the root password now? I wasn’t totally out of luck. 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 I could find the password reset option in its ‘Access’ tab. See below:

With that option I was able to receive a new temporary root password in my inbox. (to the email address your digital ocean account is registered to). I returned back to my ssh console and pasted the password I got from Digital ocean. It logged me in as root user but 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 successfully logged in as root. Then I could reset the password for ‘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 🙂

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar



Do NOT follow this link or you will be banned from the site!