What are the contents of /bin/bash, and what do I do if I accidentally overwrote them
Don't shut down your machine.
Do you still have a running shell? Is it bash? If so, you're fine. (But don't do this again.)
Run:
sudo cp /proc/$$/exe /bin/bash
Voila, all is well.
Since someone in the comments doubts that this works:
[vagrant@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
[vagrant@localhost ~]$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[vagrant@localhost ~]$ echo $0
-bash
[vagrant@localhost ~]$ sudo rm /bin/bash
[vagrant@localhost ~]$ bash
-bash: /bin/bash: No such file or directory
[vagrant@localhost ~]$ sudo su -
su: /bin/bash: No such file or directory
[vagrant@localhost ~]$ sudo cp /proc/$$/exe /bin/bash
[vagrant@localhost ~]$ bash
[vagrant@localhost ~]$ exit
[vagrant@localhost ~]$ sudo su -
[root@localhost ~]# logout
[vagrant@localhost ~]$
bash
is a shell, probably your system shell, so now weird things happen, while parts of the shell are still in memory. Once you log out or reboot, you,ll be in deeper trouble.
So the first thing should be to change your shell to something safe. See what shells you have installed
cat /etc/shells
Then change your shell to one of the other shells listed there, for example
chsh -s /bin/dash
Update, because you already rebooted:
You are lucky that nowadays the boot process doesn't rely on bash
, so your system boots, you just can't get a command line. But you can start an editor to edit /etc/passwd
and change the shell in the root
line from /bin/bash
to /bin/dash
. Log out and log in again. Just don't make any other change in that file, or you may mess up your system completely.
Then try to reinstall bash
with
apt-get --reinstall install bash
If everything succeeded you can chsh
back to bash
.
Finally: I think, kali is a highly specialized distribution, probably not suited for people who accidently overwrite their shell. As this sentence was called rude and harsh, I should add that I wrote it out of my own experience. When I was younger, I did ruin my system because nobody told me to avoid messing around as root.
If you can login, but you can’t open a terminal or otherwise access a shell,
but you can access files through the GUI, go to /bin
,
look for files whose names end with sh
(but not .sh
)
and run one (by double-clicking or right-clicking).
In particular, look for the following:
sh
dash
ash
ksh
(orksh
followed by a number; e.g.,ksh93
)zsh
yash
or, as a last resort,
tcsh
orcsh
If you can get a shell running, then try Philippos’s answer.
Another approach is to boot into single-user mode
following these instructions
but specify init=/bin/sh
(or one of the other shells)
instead of init=/bin/bash
.