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:
/etc/profile
; ~/.profile
- bash:
/etc/profile
; ~/.bash_profile
, if absent ~/.bash_login
, if absent ~/.profile
.
- zsh:
/etc/zshenv
, /etc/zprofile
, /etc/zlogin
, /etc/zshrc
(if interactive); ~/.zshenv
, ~/.zprofile
, ~/.zlogin
, ~/.zshrc
(if interactive)
- csh, tcsh:
~/.login
- fish:
/usr/share/fish/config.fish
, /etc/fish/config.fish
; ~/.config/fish/config.fish`
These files may load other files; in particular many distributions set up /etc/profile
to load files in /etc/profile.d
.
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 /etc/profile
and ~/.profile
.
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 rshd
or sshd
even though the shell isn't interactive.)
- Access the account over FTP or SFTP.