When you log in on a text mode console or over the network, your login shell is executed. It reads some system-wide and per-user configuration files; here are the most common ones (if your shell isn't listed here, refer to its documentation):
- sh, ksh:
~/.bash_profile, if absent
~/.bash_login, if absent
/etc/zshrc (if interactive);
~/.zshrc (if interactive)
- csh, tcsh:
These files may load other files; in particular many distributions set up
/etc/profile to load files in
If any of these files contains something that causes the shell to exit, you'll be logged out without having the opportunity to type a command.
You can add a line containing
set -x to the top of the applicable file to see a trace of the commands that are executed. (That's for Bourne-style shells; use
set echo in csh, and fish has no such thing)
When you log in via the GUI (on a display manager), your login shell isn't executed; however most systems arrange to run either sh or bash and load
If you're stuck because you can't log in:
- Try pressing Ctrl+C during the login sequence. If you hit it at the right time, it'll interrupt the shell just as it's starting to load the profile file and you'll get a command line.
- Run commands over the network.
ssh mymachine.example.com 'mv .profile no.profile' moves a problematic
~/.profile out of the way; it doesn't load the profile files because the remote shell isn't a login shell. (But bash is weird: it loads
.bashrc if its parent is
sshd even though the shell isn't interactive.)
- Access the account over FTP or SFTP.