Accidentally modified .bashrc and now I cant login despite entering password correctly
I messed up bigtime with the bashrc file. I was installing Gurobi and I had to set path variables in the bashrc file. So, I replaced all the text in bashrc with the path variables and saved the bashrc file. And I also made sure, if anything bad happens, I have a backup of this file. The original unmodified backup file is in the Downloads folder.
Now when I restarted the system, I was not able to login despite giving the proper password. Hence, I'd like to ask you for some help. What kind of fixes are possible given the fact that I still have the bashrc file in the Downloads directory
Solution 1:
Use LiveUSB or LiveDVD.
Boot into live session, mount your hard-drive, and copy your original .bashrc
file over the modified.
Then you can safely reboot (eject USB or DVD).
General info: In case you wouldn't have backup of .bashrc
file, you can use the one from liveUSB/DVD.
Solution 2:
You should be able to boot into recovery mode, which will let you drop into a root shell and then correct the problem from there. This avoids the need to download an additional OS.
Instructions taken from Ubuntu wiki:
- Switch on your computer.
- Wait until the BIOS has finished loading, or has almost finished. (During this time you will probably see a logo of your computer manufacturer.)
Quickly press and hold the Shift key, which will bring up the GNU GRUB menu. (If you see the Ubuntu logo, you've missed the point where you can enter the GRUB menu.)
Select the line which starts with "
Advanced options
".Select the line ending with "
(recovery mode)
", probably the second line, something like:
Ubuntu GNU/Linux, with Linux 3.8.0-26-generic (recovery mode)
Press Return and your machine will begin the boot process.
After a few moments, your workstation should display a menu with a number of options. One of the options (you may need to scroll down to the bottom of the list) will be "
Drop to root shell prompt
". Press Return with this option highlighted.The root partition is mounted read-only. To mount it read/write, enter the command
mount -o remount,rw /
If you have /home, /boot, /tmp, or any other mount point on a separate partition, you can mount them with the command
mount --all
(This must be done following step 8 so that
/etc/mtab
is writable.)
If you do not have the recovery option, you can press e in GRUB to edit the standard boot option and add recovery
at the end of the linux
line (second-last line by default, just before initrd
). Then press F10 to run it.
Solution 3:
Use a live CD
- Boot using live CD/DVD. In case you do not have the iso and do not want to download the large iso, download Tiny Core - 10MB.
- On a command line type
sudo mount /dev/sdXn /mnt
wheresdXn
is your Ubuntu partition. - Type
cd /mnt/home/<your user name>/Downloads
. - Now restore your
.bashrc
as your new.bashrc
using this commandmv ../.bashrc ../.bashrc_old && cp ./.bashrc ../
. - Now restart into your system and you should be good to go.
Solution 4:
Insert the dvd or USB you used to install Ubuntu and boot from it. Pick "try Ubuntu" and wait for it to return the desktop.
Check the disks in the lauchers for the one that has your home. Clicking it mounts it into /media/
Open a terminal and cd
into it to your Downloads and copy the file into your home. That would be:
cd /media/home/{your_username}/Downloads/
sudo cp .bashrc ../
and reboot without the dvd/USB.