What is .bash_profile?
Bash is the program that reads the commands you type. .bash_profile is a small file in your home folder. Bash reads it each time you log in. It sets things up for you, such as shortcuts and paths. The dot at the start hides the file. If a bad line sits in the file, login can break or close at once.
You may need root access for this guide. Root is the main administrator login of the server.
Steps
- Log in as root, or use the console in your VPS panel if SSH closes at once. A console is a window that talks to the server directly.
- Go to the home folder of the user with the problem. For the root user:
For another user, usecd /rootcd /home/username. - Make a copy of the broken file first.
This keeps the old file safe so you can read it later.cp .bash_profile .bash_profile.broken - Open the file in an editor.
nano .bash_profile - Look for lines you did not write. Look for typos, missing quotes, or an
exitline. Remove or fix them. - Press Ctrl+O, then Enter to save. Press Ctrl+X to leave.
- Test the file.
This checks for syntax mistakes without running anything. No output means no errors.bash -n .bash_profile
If you want to start fresh
Copy a clean sample from the system. Do this only if you do not need your old settings.
cp /etc/skel/.bash_profile ~/.bash_profile
This replaces your file with the standard one. The folder /etc/skel holds the default files for new users. The ~ sign means your home folder.
A typical clean file on Red Hat style systems has these lines:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH
The first part loads your .bashrc file. The last lines add your own bin folder to the search path.
.broken copy first.Also check .bashrc, because the same kind of mistake can sit there.
Quick recap
.bash_profileruns each time you log in.- Use the console if SSH will not stay open.
- Copy the broken file, edit it, and test with
bash -n. - Or restore the default from
/etc/skel.