0

I accidentally created an account on Debian with the naming convention below:

Strange looking character

Can anyone tell me how do I delete this? I entered "^Xclear"

terdon
  • 234,489
  • 66
  • 447
  • 667
  • Welcome to Unix SE! I could be wrong, but you (might) need to install a font - look at my post here (I had the exact same problem, viewing symbols appeared just like that ) https://unix.stackexchange.com/questions/636530/viewing-runes-font-installation/636531#636531 Hope it can at least help somewhat! – William Martens Feb 28 '21 at 14:21
  • Hey thanks for the reply. I have installed the junicode fonts, but how do I enter the weird font to userdel? – Ong Bang Rui Feb 28 '21 at 14:28
  • I thought of maybe, running something like in python3: >>> ord('character') will print out it's value, and - from there one could work out what character it is, – William Martens Feb 28 '21 at 14:34
  • I created the account within a bash script via user input. I didn't know you could enter such weird values into the input. I am learning linux, so everything is pretty foreign to me :) – Ong Bang Rui Feb 28 '21 at 15:07
  • i am using debian btw – Ong Bang Rui Feb 28 '21 at 15:07
  • 3
    Please post the actual contents of your `/etc/passwd` file. The image is useless: that just shows the glyph your chosen font will show for that character but we need the actual data to understand better. How did you create this file? You say "you entered '^Xclear", but entered it where? And how did you enter the `^X`? Do you mean you pressed the Ctrl key and then X? Please [edit] your question and give us more context. – terdon Feb 28 '21 at 15:10
  • If it is the last line in your /etc/passwd then please add output of `tail -n 1 /etc/passwd | hexdump -C` to your question. – Cyrus Feb 28 '21 at 16:32
  • @terdon sorry to interrupt, isn't that a extremely bad idea?(Or have I misunderstood something?) isn't the passwd file, quite - uh, "private" ? Edit: Sorry, Did I confuse the passwd file with the shadow file? – William Martens Feb 28 '21 at 17:09
  • 2
    @WilliamMartens Yes, `/etc/passwd` is perfectly fine to share, it only has the user name, user id, home dir etc. Nothing sensitive. But that would help us give a one-liner to remove the user with `userdel`. Otherwise, the OP will need to manually edit `/etc/passwd`, `/etc/shadow` and `/etc/group` to remove mention of the user. – terdon Feb 28 '21 at 17:23
  • @terdon Oh :facepalm: thanks for explaining. I totally confused the two. – William Martens Feb 28 '21 at 17:23

1 Answers1

2

User accounts are typically defined by their presence in two files, and a home directory devoted to the account. You might also have created a group with this strange character in it. The two files are /etc/passwd and /etc/shadow and the directory is typically under /home/. Groups are defined in /etc/group.

Warning: the following edits important system files in place. If you are worried about that going wrong, copy these files before hand with something like this sudo cp /etc/passwd /etc/shadow /etc/group /root/. You can always copy them back with sudo cp /root/passwd /root/shadow /root/group /etc/.

In your case, the following two edits should remove the lines from the user files:

/etc/passwd:
   $ sudo sed -i.bak  -e '/.*\:1003\:1003\:.*/d' /etc/passwd
/etc/shadow:
   $ sudo sed -i.bak -e '/^.clear\:.*/d' /etc/shadow

At this point, the account will be effectively deleted. The -i .bak options are a safety measure: they will cause sed to create a backup copy of the original files with the .bak extension (e.g. /etc/passwd.bak). This can help you recover if you break anything.

There are two other things you might want to do to clean up:

One is to look in /etc/group and see if you also created a group with this strange character in it? Something like this would delete it:

/etc/shadow:
   $ sudo sed -i -e '/^.clear\:.*/d' /etc/group

Finally, if you look in the /home/ directory, do you see a strangely named directory? You can rename it with sudo mv /home/?clear /home/was-clear and then, when you are sure it is the right directory etc, remove it with sudo rm -rf /home/was-clear.

terdon
  • 234,489
  • 66
  • 447
  • 667
Tinkerer
  • 148
  • 5
  • 2
    This is one of the cases where I would definitely suggest opening an actual root shell (e.g. with `sudo -s`) before doing anything, since messing up `passwd` and `shadow` badly enough might prevent being able to log in or run `sudo`. It _might_ not be necessary, since I _think_ the `root` user would be recognized if the lines related to it are intact, even if the rest of the files are messed up, but keeping the shell open helps to be sure. Also you could just run `vipw` and `vipw -s` and delete the lines involved with the editor. – ilkkachu Feb 28 '21 at 17:03