当前位置: 首页>>技术教程>>正文


意外修改的.bashrc,尽管输入了正确的密码,但我仍然无法登录

,

问题描述

我用bashrc文件弄乱了bigtime。我正在安装Gurobi,并且必须在bashrc文件中设置路径变量。因此,我用路径变量替换了bashrc中的所有文本,并保存了bashrc文件。而且我还确保,如果发生任何不好的情况,我都有该文件的备份。原始的未修改备份文件位于“下载”文件夹中。

现在,当我重新启动系统时,尽管输入了正确的密码,但我仍无法登录。因此,我想向您寻求帮助。鉴于我在Downloads目录中仍然有bashrc文件,可以进行什么样的修复

最佳方案

使用LiveUSB或LiveDVD。

进入实时会话,安装hard-drive,然后将原始的.bashrc文件复制到修改后的文件中。

然后,您可以安全地重新启动(弹出USB或DVD)。

常规信息:如果您没有.bashrc文件的备份,则可以使用liveUSB /DVD中的一个。

次佳方案

您应该能够使用boot into recovery mode,这将使您放入根shell,然后从那里更正问题。这样避免了下载其他操作系统的需要。

取自Ubuntu Wiki的说明:

  1. Switch on your computer.
  2. Wait until the BIOS has finished loading, or has almost finished. (During this time you will probably see a logo of your computer manufacturer.)
  3. 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.)

  4. Select the line which starts with “Advanced options“.

  5. 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)

  6. Press Return and your machine will begin the boot process.

  7. 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.

  8. The root partition is mounted read-only. To mount it read/write, enter the command

    mount -o remount,rw /

  9. 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.)

如果没有恢复选项,则可以按GRUB中的e编辑标准启动选项,并在linux行的末尾添加recovery(默认为second-last行,在initrd之前)。然后按F10运行它。

第三种方案

使用现场CD

  1. 使用实时CD /DVD引导。如果您没有iso并且不想下载大型iso,请下载Tiny Core-10MB。

  2. 在命令行上,输入sudo mount /dev/sdXn /mnt,其中sdXn是您的Ubuntu分区。

  3. 输入cd /mnt/home/<your user name>/Downloads

  4. 现在,使用此命令mv ../.bashrc ../.bashrc_old && cp ./.bashrc ../.bashrc还原为新的.bashrc

  5. 现在重新启动系统,您应该一切顺利。

第四种方案

插入用于安装Ubuntu的DVD或USB并从中启动。选择”try Ubuntu”,然后等待它返回桌面。

检查lauchers中有您家的磁盘。单击它会将其装入/media /

打开一个终端,并在其中下载cd到您的下载文件中,然后将文件复制到您的家中。那将是:

cd /media/home/{your_username}/Downloads/
sudo cp .bashrc ../

并在没有DVD /USB的情况下重新启动。

第五种方案

通过SFTP连接

从另一台Linux计算机的内置 sftp命令或具有WinSCP或FileZilla的PC通过SFTP连接到系统,然后修复文件。 .bashrc文件通常不包含在SFTP中(可以对authorized_keys文件进行调整以使其包含在其中,但您怀疑这样做了)。

第六种方案

我建议总是有两个sudo帐户。如果您为该帐户提供普通密码,则这些帐户在所有情况下都可以充当ALMOST的根用户。您暂时成为root。

如果您搞砸了一个帐户,则可以与另一个帐户一起解决。

但是,如果您知道密码,则可以使用REGULAR帐户和’su screwed-up-sudo-account-name’。然后,您将充当搞砸的帐户,并且可以在’dc /home/screwed-up-account’之后执行“ sudo cp backup .bashrc”操作,但现在可以不搞砸了,但是不确定您的具体情况。

第七种方案

正如少数人所说,最好的方法是开设一个”sudo”帐户。其次,如果您对.bashrc文件进行了大量修改,请在开始修补之前将其副本放到 memory 棒上,然后不必从头开始,可以返回到上一个已知商品。 bashrc文件,而不会丢失以前的所有修改。修改.bashrc或.vimrc或。时,我做的第一件事。 。 。在开始之前,任何配置文件都会复制到我的随身 memory 棒中。我是人类,我有孩子,我会分心。我的 memory 棒中充满了用于bash,vim,conky,openbox,tint2等的配置文件。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/10582.html,未经允许,请勿转载。