Is there a way to recover my username in Kali Linux?

I forgot my username in Kali Linux and can no longer login. Is there any way to view usernames?


Solution 1:

Usernames are listed in /etc/passwd.

It is quite long, because it contains various system users too. Real users usually start with UID 1000. UID is the third column in the :-separated table, username is the first column.

But to see it, you have to be logged in the machine somehow. If you know any other login and corresponding password, use it and look there.

If you can't login, but can reboot, there are two options:

  • boot from a live CD
  • pass init=/bin/bash parameter to kernel. That will get you a root shell without logging in or anything, but system initialization won't be done either (but /etc/ has to be on the root filesystem and that will be mounted).

Solution 2:

That sounds really weird. Was it that complex?

First idea coming to my mind, if you're still able to mount your hard disk (using a live CD or another account you've got access to), you could just look and see what sub folders are inside /home. Theoretically, there should be one for each user.

To expand a bit on this, you could probably do something like this:

cat /etc/passwd | grep /home

This should get you a list of all users having a home directory.

You'll get some output like this (example from my Raspberry Pi running Raspbian):

pi@raspberrypi ~ $ cat /etc/passwd | grep /home
pi:x:1000:1000:,,,:/home/pi:/bin/bash
ntp:x:102:104::/home/ntp:/bin/false
usbmux:x:105:46:usbmux daemon,,,:/home/usbmux:/bin/false
git:x:1001:1004:,,,:/home/git:/usr/bin/git-shell

As you can see, there are a few system accounts not accessible (ntp and usbmux), but there are also two real user accounts (pi and git).

So to expand a bit, you could remove all lines with false as their shell:

cat /etc/passwd | grep /home | grep -v /bin/false

This will - in my case - return all user accounts (there might still be some system stuff though):

pi@raspberrypi ~ $ cat /etc/passwd | grep /home | grep -v /bin/false
pi:x:1000:1000:,,,:/home/pi:/bin/bash
git:x:1001:1004:,,,:/home/git:/usr/bin/git-shell