0

I was editing my .bash_profile and .bash_login, and I accidentally added a circular reference so that two files were including each other. After closing the session and trying to sign in again, the circular reference hangs the process. Fortunately, this was on WSL so I can edit the file using Windows, and I also had a separate session still open so I didn't even need to.

However, hypothetically if this was not the case, how would one sign in to Linux without loading the profile files, or how could one sign in and remove the circular reference?

mbomb007
  • 123

2 Answers2

1
  1. Boot to runlevel 1.
  2. Enter the root password when prompted.
  3. Fix your mistakes.
  4. Reboot.
0

Since the problem is with bash (running interactively), if you have remote ssh access and an alternative shell, you could login using it. For example, to login with dash you'd do:

ssh -t user@host /bin/dash

And then fix your bash startup files.

Note that bash will still run (if it is your login shell), but it will not interpret .bashrc because it is not interactive. So you'll be able to fix that file.

The accepted answer to this question What is the purpose of .bashrc and how does it work? explains when .bashrc is not run.

  • 2
    Not necessarily. If the login shell is bash, it will still be used to run /bin/dash. The problem is Bash tries to detect if it's executed by a remote shell daemon and if so, it sources .bashrc despite the fact it's not interactive. I'm not sure how it works in WSL but I know e.g. in Linux bash run from sshd does this. We can hope .bashrc itself checks if the shell is interactive (see "twist number 2" and "twist number 3" here). – Kamil Maciorowski Feb 25 '21 at 20:42
  • @KamilMaciorowski I clarified your concern. The OP wants to login and fix .bashrc, and this will allow for that. (you can check it by adding some command to .bashrc and see if it runs when invoked this way). – Eduardo Trápani Feb 25 '21 at 21:06
  • Yes, the added command runs (tested on Debian 10 server, Bash 5.0.3, sshd). My first comment stands. – Kamil Maciorowski Feb 25 '21 at 21:42
  • @KamilMaciorowski It does not run for me when I do ssh -t user@host /bin/dash. The very same system. Note that bash will not run interactively if it is given a command (in this case -c /bin/dash) and so it will not use .bashrc. Check this What is the purpose of .bashrc and how does it work? for the details and some simple examples. – Eduardo Trápani Feb 25 '21 at 22:04
  • AFAIK the default (skeletal) .bashrc in Debian 10 starts with code that tests if the shell is interactive. To see if the file gets sourced I added a command before the test. – Kamil Maciorowski Feb 25 '21 at 22:07
  • What I'm talking about is documented under "Invoked by remote shell daemon" here. It appears none of the answers to the question you linked to notices this behavior. – Kamil Maciorowski Feb 25 '21 at 22:24